Skip to content

becker/conversion

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Unit Conversion

This package helps to convert units. It was forked from abhimanyu003/conversion repository.

Units supported

  • Acceleration
  • Angle
  • Area
  • Storage
  • Current
  • Fuel
  • Length
  • Mass
  • Pressure
  • Speed
  • Temperature
  • Time
  • Voltage
  • Volume

Installation

composer require becker/conversion

Register the Service Provider

NOTE: You can skip this step if you are using Laravel 5.5 or higher. The package is automatically registered, due to the package discovery feature.

Open up the config/app.php and register the new Service Provider:

//config/app.php

/*
 * Package Service Providers...
 */

Becker\Conversion\ConversionServiceProvider::class

//...

You can also register the Alias:

'Conversion'  => Becker\Conversion\Facades\Conversion::class

How to use

Conversion::convert($value, 'type')->to('another_type');

Example:

  • Converting MB to KB
Conversion::convert(1, 'megabyte')->to('kilobyte');
// 1.024,00 (two decimal places)
  • Converting mm to cm
Conversion::convert(1000, 'millimeter')->to('centimeter');
  • Converting kg to g
Conversion::convert(1, 'kilogram')->to('gram');

Formatting results:

Conversion::convert($value, 'type')->to('another_type')
->format(int decimal, 'decimal place modifier', 'thousand place modifier');

Example:

Conversion::convert(1, 'megabyte')->to('kilobyte')->format(0,'.',',');
// 1,024 (no decimal place)

Conversion Chart

Acceleration

  • METRE_PER_SECOND_SQUARE

Angle

  • TURN
  • RADIAN
  • DEGREE
  • GRADIAN

Area

  • SQUARE_METER
  • HECTARE
  • SQUARE_KILOMETER
  • SQUARE_INCH
  • SQUARE_FEET
  • SQUARE_YARD
  • ACRE
  • SQUARE_MILE

Storage

  • BIT
  • BYTE
  • KILOBIT
  • KILOBYTE
  • MEGABIT
  • MEGABYTE
  • GIGABIT
  • GIGABYTE
  • TERABIT
  • TERABYTE
  • PETABIT
  • PETABYTE

Current

  • STATAMPERE
  • MICROAMPERE
  • MILLIAMPERE
  • AMPERE
  • ABAMPERE
  • KILOAMPERE

Fuel

  • KILOMETERS_PER_LITRE
  • LITRE_PER_100_KILOMETER
  • MILES_PER_GALLON
  • US_MILES_PER_GALLON

Length

  • MILLIMETER
  • CENTIMETER
  • METER
  • KILOMETER
  • INCH
  • FOOT
  • YARD
  • MILE
  • NAUTICAL_MILE

Mass

  • MICROGRAM
  • MILLIGRAM
  • GRAM
  • KILOGRAM
  • METRIC_TON
  • OUNCE
  • POUND
  • STONE
  • SHORT_TON
  • LONG_TON

Pressure

  • PASCAL
  • KILOPASCAL
  • MEGAPASCAL
  • BAR
  • MILLIMETERS_OF_MERCURY
  • INCHES_OF_MERCURY
  • POUNDS_PER_SQUARE_INCH
  • ATMOSPHERE

Speed

  • METER_PER_SECOND
  • KILOMETERS_PER_HOUR
  • FEET_PER_SECOND
  • MILES_PER_HOUR
  • KNOT

Temperature

  • CELSIUS
  • FAHRENHEIT
  • KELVIN

Time

  • NANOSECOND
  • MICROSECOND
  • MILLISECOND
  • SECOND
  • MINUTE
  • HOUR
  • DAY
  • WEEK
  • MONTH
  • YEAR
  • DECADE
  • CENTURY
  • MILLENIUM

Voltage

  • VOLT
  • KILOVOLT

Volume

  • MILLILITRE
  • LITRE
  • CUBIC_METER
  • GALLON
  • QUART
  • PINT
  • TABLESPOON
  • TEASPOON
  • US_GALLON
  • US_QUART
  • US_PINT
  • US_CUP
  • US_OUNCE
  • US_TABLESPOON
  • US_TEASPOON
  • CUBIC_INCH
  • CUBIC_FOOT

Contribute

Feel free to contribute and update the repository.

About

Laravel Unit Conversion

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%