Sample Header Ad - 728x90

Rounding 2.555500000000000104805053 with printf -> 2.555 or 2.556?

0 votes
0 answers
59 views
I tried
printf "%.3f\n" 2.555500000000000104805053
printf "%.3f\n" 2.555500000000000104805054
the result was
2.555
2.556
same with printf "%.3f\n" 3.555500000000000104805053 But 0.555500..., 1., 4., 5., 6., 7., 8., 9. are correct -> x.556 What is the problem with rounding with printf? - MacOS Ventura 13.2 - The shell is zsh 5.8.1 (x86_64-apple-darwin22.0), but it appears also in bash-3.2 - In ksh (shell) the output is identical (2.556) with both commands
Asked by R 9000 (167 rep)
Feb 27, 2023, 10:35 PM
Last activity: Feb 28, 2023, 08:54 AM