My code :
$baseprice=1705000/1.1;
var_dump($baseprice);
$parseprice=intval($baseprice);
var_dump($parseprice);
Result :
float(1550000) int(1549999)
As you can see, i lost 1 number when convert from float to int, where is it,what solution for this case for convert without lost data, Thanks.
You are using floating point numbers which will lose precision (see this link).
If you are handling currency use integers and work in cents, pence, pfennigs, or whatever. Convert to a currency format just before display.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With