Reputation: 8833
I have an issue with php 5.6 rounding to two decimals. If you test the following it will export $y exactly as 19.620000000000001
I know there are solutions to display it using number_format, but how do I make it to be exactly 19.62?
Thanks.
$x = 19.620000000000001;
$y = round($x, 2);
var_export($y);
Later Edit. I need it for exact math operations, not display.
Upvotes: 0
Views: 99
Reputation: 29
It's because you're using var_export
Try using echo
or var_dump()
$x = 19.620000000000001;
$y = round($x, 2);
echo $y;
Upvotes: 2
Reputation: 2438
If you do number_format:
$y = number_format($x, 2);
The $y
will have 2 decimals but it will also be a string. Not sure if it's satisfactory.
Upvotes: 0
Reputation: 816
Try using echo
to display your output. It will give you your desired output
Upvotes: 3