adityar15 / converter
此包允许您以最简单的方式转换大多数指标。
v1.0
2021-03-04 18:47 UTC
README
此包允许您以最简单和最有效的方式转换大多数指标。
使用以下命令进行安装
composer require adityar15/converter
此包支持Laravel版本6.*、7.*、8.*
安装后,您可以在控制器或其他使用位置导入此包,如下所示
use adityar15\converter\Converter;
长度/距离转换
此包的主要功能是您可以通过最有效的方式进行转换。
- 厘米转换为英尺及反之
//Converter::CmtoFeet(float $value, bool $precise=true)
//the precise parameter is true by default. If set to false then value is rounded to nearest ceil value.
return Converter::CmtoFeet(178)
//this will return 5' 10.1''
//Converter::FeettoCm(string $value, int $digits=2);
//This will convert the feet value in string to centimeter in float. The value in feets is given in format 5-10 for 5feet 10inch or 5-0 or 5feet 0inch. The '-' format is //mandatory. The digits is number of digits after decimal. By default it is set to 2.
return Converter::FeettoCm('5-8.5', 2);
//this will return 173.99
- 英寸转换为英尺及反之
//Converter::InchtoFeet(float $value, bool $precise=true)
//the precise parameter is true by default. If set to false then value is rounded to nearest ceil value.
return Converter::InchtoFeet(70)
//this will return 5' 10''
//The inverse is also possible and very similar to FeettoCm function
return Converter::FeettoInch('5-10', int $digits=2);
//this will return 70.00
- 米转换为英尺及反之
//Converter::MetertoFeet(float $value, bool $precise=true)
//the precise parameter is true by default. If set to false then value is rounded to nearest ceil value.
return Converter::MetertoFeet(1.78)
//this will return 5' 10.1''
//The inverse is also possible and very similar to FeettoCm function
return Converter::FeettoMeter('5-10', int $digits=2);
//this will return 1.78
此外,您还可以转换为
- 米转换为厘米及反之
return Converter::MetertoCm(1, 2) //(float $value, int $digits) by default digits is 2
//this will return 100.00
//to convert centimeter to meter
return Converter::CmtoMeter(100, 2) //(float $value, int $digits) by default digits is 2
//this will return 1.00
- 米转换为英寸及反之
return Converter::MetertoInch(1, 2) //(float $value, int $digits) by default digits is 2
//this will return 39.37
//to convert inch to meter
return Converter::InchtoMeter(39.37, 2) //(float $value, int $digits) by default digits is 2
//this will return 1.00
- 厘米转换为英寸及反之
return Converter::CmtoInch(2.54, 2) //(float $value, int $digits) by default digits is 2
//this will return 1.00
//to convert inch to centimeter
return Converter::InchtoMeter(1, 2) //(float $value, int $digits) by default digits is 2
//this will return 2.54
重量转换
您还可以转换重量。以下转换支持
- 克转换为千克及反之
//to convert from gram to kilogram
return Converter::GtoKg(2000, 2); //(float $value, int $digits) by default digits is 2
//This will return 2.00
//To convert Kilogram to Gram
return Converter::GtoKg(2, 2); //(float $value, int $digits) by default digits is 2
//This will return 2000.00
- 克转换为磅
Converter::GtoPound(float $value, int $digits) // by default digits is 2
- 克转换为盎司
Converter::GtoOunce(float $value, int $digits) // by default digits is 2
- 克转换为毫克
Converter::GtoMg(float $value, int $digits) // by default digits is 2
目前,您无法直接从千克转换为磅。在这种情况下,您需要将千克转换为克,然后再将克转换为磅。