Library help to convert units.
- Acceleration
- Angle
- Area
- Storage
- Current
- Fuel
- Length
- Mass
- Pressure
- Speed
- Temperature
- Time
- Voltage
- Volume
- Add below line to
composer.json
// ...
"abhimanyusharma003/conversion": "dev-master"
// ...
-
Run
composer update
orcomposer install
-
Open
app/config/app.php
and add the service provider to yourproviders
array.
// ...
'Abhimanyusharma003\Conversion\ConversionServiceProvider',
// ...
Conversion::convert($value,'type')->to('type');
Formatting results use
Conversion::convert($value,'type')->to('type')
->format(int decimal,'decimal modifier','thousand modifer');
- Converting MB to kb
Conversion::convert(1, 'MB')->to('kB'); // output 1,024.00 ( two decimal place )
// Formatting the output
Conversion::convert(1, 'MB')->to('kB')->format(0,'.',','); // output 1,024 ( no decimal place )
- Converting mm to cm
Conversion::convert(1000,'mm')->to('cm');
- Converting mm to cm
Conversion::convert(1000,'mm')->to('cm');
- Converting kg to g
Conversion::convert(1,'kg')->to('g');
METRE_PER_SECOND_SQUARED = 'm/s^2';
TURN = 'turn';
RADIAN = 'rad';
DEGREE = 'deg';
GRADIAN = 'grad';
// Metric system
SQUARE_METRE = 'm^2';
HECTARE = 'ha';
SQUARE_KILOMETRE = 'km^2';
// Imperial system
SQUARE_INCH = 'in^2';
SQUARE_FEET = 'ft^2';
SQUARE_YARD = 'yd^2';
ACRE = 'ac';
SQUARE_MILE = 'mi^2';
BIT = 'b';
BYTE = 'B';
KILOBIT = 'kb';
KILOBYTE = 'kB';
MEGABIT = 'Mb';
MEGABYTE = 'MB';
GIGABIT = 'Gb';
GIGABYTE = 'GB';
TERABIT = 'Tb';
TERABYTE = 'TB';
PETABIT = 'Pb';
PETABYTE = 'PB';
STATAMPERE = 'statA';
MICROAMPERE = 'uA';
MILLIAMPERE = 'mA';
ABAMPERE = 'aA';
AMPERE = 'A';
KILOAMPERE = 'kA';
// Metric units
KILOMETRES_PER_LITRE = 'km/L';
LITRE_PER_100_KILOMETRES = 'L/100 km';
// Imperial units
MILES_PER_GALLON = 'mpg';
// US units
US_MILES_PER_GALLON = 'us mpg';
// Metric system
MILLIMETRE = 'mm';
CENTIMETRE = 'cm';
METRE = 'm';
KILOMETRE = 'km';
// Imperial system
INCH = 'in';
FOOT = 'ft';
YARD = 'yd';
MILE = 'mi';
// Other systems
NAUTICAL_MILE = 'nmi';
// Metric system
MICROGRAM = 'mcg';
MILLIGRAM = 'mg';
GRAM = 'g';
KILOGRAM = 'kg';
METRIC_TON = 't';
// Imperial system
OUNCE = 'oz';
POUND = 'lb';
STONE = 'st';
SHORT_TON = 's. t.';
LONG_TON = 'l. t.';
PASCAL = 'Pa';
KILOPASCAL = 'kPa';
MEGAPASCAL = 'MPa';
BAR = 'bar';
MILLIMETRES_OF_MERCURY = 'mmHg';
ATMOSPHERE = 'atm';
INCHES_OF_MERCURY = 'inHg';
POUNDS_PER_SQUARE_INCH = 'psi';
// Metric units
METRE_PER_SECOND = 'm/s';
KILOMETRES_PER_HOUR = 'km/h';
// Imperial units
FEET_PER_SECOND = 'ft/s';
MILES_PER_HOUR = 'mph';
// Other units
KNOT = 'kn';
CELSIUS = 'C';
FAHRENHEIT = 'F';
KELVIN = 'K';
NANOSECOND = 'ns';
MICROSECOND = 'us';
MILLISECOND = 'ms';
SECOND = 's';
MINUTE = 'min';
HOUR = 'hr';
DAY = 'd';
WEEK = 'wk';
MONTH = 'mo';
YEAR = 'a';
DECADE = 'decade';
CENTURY = 'century';
MILLENIUM = 'ka';
VOLT = 'V';
KILOVOLT = 'KV';
// Metric system
MILLILITRE = 'mL';
LITRE = 'L';
CUBIC_METRE = 'm^3';
// Imperial system
GALLON = 'gal';
QUART = 'qt';
PINT = 'pt';
CUP = 'c';
TABLESPOON = 'tbsp';
TEASPOON = 'tsp';
// US system
US_GALLON = 'us gal';
US_QUART = 'us qt';
US_PINT = 'us pt';
US_CUP = 'us c';
US_OUNCE = 'us oz';
US_TABLESPOON = 'us tbsp';
US_TEASPOON = 'us tsp';
// Other units
CUBIC_INCH = 'in^3';
Feel free to contribute and update the rep.