I wonder that you are surprised by your results.

I assume that you know that float arithmetic is generally not absolutely exact 
in computers. One reason is, that not every fractional decimal number can be 
exactly represented in binary floating point format. So when we have three 
floating point numbers a, b, b then generally (a + b) + c != a + (b + c). See

> [https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems](https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems)

So it can not surprise that the rounding proc does not always give the exactly 
same result as the value which is obtained from the string representation.

I don't know what your concrete problem is in real life application. When you 
do rounding, and print the result with a limited number of digits I guess it 
should be fine, as the error is in the very tiny places which generally are not 
printed at all. Always converting the rounded result to string and back to 
float may help when the same proc is used as Nim compiler use internally for 
processing float literals, but that is slow. Maybe you can tell us where 
exactly you got problems in your real life application.

Reply via email to