Problem: keep one decimal point, not rounded. if it is an integer, add 0. many people say sprintf (& #039; %. 1f & #039;, $ str);, but there is still a problem with the obtained result. Finally, this solution is used: echosprintf (& #039; %. 1f & #039;, floor ($ str); {code ...} isn't it about rounding it out? Why... problem: keep 1 decimal place, not rounded up, and add 0 to an integer
Many people use it.sprintf('%.1f',$str);
But the result is still incorrect,
Finally, this solution is used:echo sprintf('%.1f', floor($str));
Isn't it about rounding it out? Why is it rounded to 5, but not to 6;
Other functionsnumber_format($str)
It's all in step 5. Why?
Reply content:
Problem: keep 1 decimal point, not rounded, and add 0 to an integer.
Many people use it.sprintf('%.1f',$str);
But the result is still incorrect,
Finally, this solution is used:echo sprintf('%.1f', floor($str));
Isn't it about rounding it out? Why is it rounded to 5, but not to 6;
Other functionsnumber_format($str)
It's all in step 5. Why?
I tested it myself. the visual test is about the accuracy of floating point representation.
Reference
Linux floating point rounding or five or six (the representation of floating point numbers is related)