adityar15/converter

此包允许您以最简单的方式转换大多数指标。

安装: 5

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放性问题: 0

类型:package

v1.0 2021-03-04 18:47 UTC

This package is auto-updated.

Last update: 2024-09-06 07:02:29 UTC


README

此包允许您以最简单和最有效的方式转换大多数指标。

使用以下命令进行安装

composer require adityar15/converter

此包支持Laravel版本6.*、7.*、8.*

安装后,您可以在控制器或其他使用位置导入此包,如下所示

use adityar15\converter\Converter;

长度/距离转换

此包的主要功能是您可以通过最有效的方式进行转换。

  1. 厘米转换为英尺及反之
//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
  1. 英寸转换为英尺及反之
//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 
  1. 米转换为英尺及反之
//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 

此外,您还可以转换为

  1. 米转换为厘米及反之
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
  1. 米转换为英寸及反之
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
  1. 厘米转换为英寸及反之
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

重量转换

您还可以转换重量。以下转换支持

  1. 克转换为千克及反之
//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
  1. 克转换为磅
Converter::GtoPound(float $value, int $digits) // by default digits is 2

  1. 克转换为盎司
Converter::GtoOunce(float $value, int $digits) // by default digits is 2

  1. 克转换为毫克
Converter::GtoMg(float $value, int $digits) // by default digits is 2

目前,您无法直接从千克转换为磅。在这种情况下,您需要将千克转换为克,然后再将克转换为磅。