ext-decimal
ext-decimal copied to clipboard
PHP Warning: Loss of data on string conversion
<?php
use Decimal\Decimal;
$s = new Decimal("71.610",3);
$e = $s+1-1;
echo $e;
?>
The code show warning "PHP Warning: Loss of data on string conversion" on line 3 but if change precision from 3 to 4: i.e. $s = new Decimal("71.610",4);
It works
Why ?
I have noticed that same issue happen when i use
$s = new Decimal("222.16",3);
Where is a problem ?
Your number has 4 significant figures, so using a precision of 3 drops the last significant figure, resulting in data loss.