dev-master
9999999-dev
MIT
The Requires
- php >=7.0
The Development Requires
by Koen Vlaswinkel
v0.1
0.1.0.0
MIT
The Requires
- php >=7.0
The Development Requires
by Koen Vlaswinkel
Wallogit.com
2017 © Pedro Peláez
This is a SI unit converter for PHP, that will convert all kinds of units from one into the other, with support for composite units., (*2)
Install with Composer:, (*3)
composer require koesie10/unit-converter
Simply create a \Vlaswinkel\UnitConverter\UnitConverter object and call the convert method:, (*4)
$converter = new \Vlaswinkel\UnitConverter\UnitConverter();
echo $converter->convert('1', 'm/s', 'km/h'); // prints 3.6, as expected
This library will try to use BC math if it is available, which is highly recommended for more accurate results. In that case, it is recommended to always supply strings to the convert function, otherwise there will still be floating point errors., (*5)
Note: If you do not get proper results, check that you have set the scale for BC math correctly. It is recommended to set the value to at least 3, but for more precision, it is recommended to increase the value more., (*6)
If you would like to use the default PHP math functions, which will have floating point errors but will not require a scale, you can instantiate the UnitConverter as follows:, (*7)
$converter = new \Vlaswinkel\UnitConverter\UnitConverter(null, new \Vlaswinkel\UnitConverter\Math\DefaultMathWrapper());
You can run automated unit tests using PHPUnit after installing dependencies:, (*8)
vendor/bin/phpunit
This library is licensed under the MIT license. See the LICENSE file for details., (*9)
MIT
MIT