Issue: Retain 1 decimal places, not rounded, 0 for integers
A lot of people say that sprintf('%.1f',$str);
, but the results are still problematic.
Finally, this method is used to solve:echo sprintf('%.1f', floor($str));
Not to say no rounding? Why by rounding, 5 but not into, 6 only into;
And all the other functions are number_format($str)
in the 5, which is why?
Reply content:
Issue: Retain 1 decimal places, not rounded, 0 for integers
A lot of people say that sprintf('%.1f',$str);
, but the results are still problematic.
Finally, this method is used to solve:echo sprintf('%.1f', floor($str));
Not to say no rounding? Why by rounding, 5 but not into, 6 only into;
And all the other functions are number_format($str)
in the 5, which is why?
I measured it, and visual inspection is the problem of the accuracy of floating point
Reference
Linux floating-point number rounding or five-six (floating-point representation)