granam / float
Converter and wrapping object for a float value
Installs: 21 848
Dependents: 11
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=7.3
- granam/number: ^5.0
Requires (Dev)
- granam/exceptions-hierarchy: ^5.0
- mockery/mockery: ^1.2
- phpunit/phpunit: ^9.0
README
Hint
First of all, make sure you don't need just a simple built-in float validation.
<?php use Granam\Float\FloatObject; $float = new FloatObject(123.456); // double(123.456) var_dump($float->getValue()); // string(7) "123.456" var_dump((string)$float); $float = new FloatObject(null); // double(0) var_dump($float->getValue()); // string(0) var_dump((string)$float); $float = new FloatObject($withTooLongDecimal = '123456.999999999999999999999999999999999999'); // double 123457 var_dump($float->getValue()); try { new FloatObject('123.999999999999999999999999999999', true /* paranoid to rounding */); } catch (\Granam\Float\Tools\Exceptions\WrongParameterType $floatException) { // Something get wrong: Some value has been lost on cast. Given string-number '123456.999999999999999999999999999999999999' results into float 123457 die('Something get wrong: ' . $floatException->getMessage()); }