Download the PHP package php-unit-conversion/php-unit-conversion without Composer
On this page you can find all versions of the php package php-unit-conversion/php-unit-conversion. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-unit-conversion/php-unit-conversion
More information about php-unit-conversion/php-unit-conversion
Files in php-unit-conversion/php-unit-conversion
Package php-unit-conversion
Short Description A fully PSR-4 compatible PHP library for converting between standard units of measure.
License MIT
Homepage https://github.com/pimlie/php-unit-conversion
Informations about the package php-unit-conversion
Php Unit Conversion
The php-unit-conversion/php-unit-conversion
package provides full PSR-4 compatible unit conversion. Most other packages that are available for unit conversion are using string
types to indicate unit types. In this package all unit types are classes.
We still need to add a lot more units and tests to make the package more usefull. If you want to help me with that, please check Contributing!
Basic Usage
Unit Conversions
Find the nearest unit type
If you have a value and want to automatically convert it to the unit type which value is closest to 1, you can use the static nearest
method.
The nearest
method should only be called on a Unit Type class.
If you only want units from a specific measurement system, you can pass a System class name as second parameter
Storing values with their type
If you want to store values in e.g. a database, you often have to store two things: the value itself and the unit type. As all our Units have a TYPE constant defined, we can use this to add the type information to the value before storing it in the database. To retrieve this unit value you can invoke the class instance itself.
The returned value is the result of first converting the value to the base value, then a shift left by 6 and add the TYPE constant.
You can use the static from
method to convert to a base unit instance again:
Arithmetic Operators
Adding custom units
Contributing
Please check Contributing for details.