in reply to A bug of sprintf or not?

Anonymous Monk is mistaken. This isn't a precision issue. It's banker's rounding.
printf("%.0f\n", 100.5); # 100 printf("%.0f\n", 101.5); # 102 printf("%.0f\n", 102.5); # 102 printf("%.0f\n", 103.5); # 104 printf("%.0f\n", 104.5); # 104 printf("%.0f\n", 105.5); # 106

Note that all those numbers (but not 100.55) can be represented precisely in floats (0.5 = 2-1).

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.