-2

How come, when I round up decimals some numbers gets wrong

echo round(0.7125, 2);

Will result in: 0.71

BUT:

echo round(0.935625, 2);

Returns: 0.93999999

Why is that?

I´m using: 5.5.45-MariaDB

Björn C
  • 3,470
  • 8
  • 37
  • 73

2 Answers2

3

You are using a comma , instead of a dot . for the decimal separator. Use :

echo round(0.935625, 2); => 0.94


Ok it seems that this is an issue of floating point precision. You are asking the system to display 0.94 which the system can't represent as a float. So it displays the nearest number it can display: 0.93999999

Thomas Ayoub
  • 28,235
  • 15
  • 95
  • 135
1
echo round(0.935625, 2);   // there is comma instead of .

Please remove comma (,) and try it

Shailesh Katarmal
  • 2,707
  • 1
  • 11
  • 15