ext-decimal icon indicating copy to clipboard operation
ext-decimal copied to clipboard

PHP Warning: Loss of data on string conversion

Open balexus opened this issue 1 year ago • 1 comments

<?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 ?

balexus avatar Mar 29 '24 10:03 balexus

Your number has 4 significant figures, so using a precision of 3 drops the last significant figure, resulting in data loss.

rtheunissen avatar Mar 29 '24 19:03 rtheunissen