While this topic is a bit old, there appears to be some misunderstanding on the ability to "round to n-digits after decimal point".
In IEEE floating-point format (and most non-IEEE formats as well) normalized values are stored as 1.bbbbbb * 2^exponent. The 'bbbbbb' is referred to as the mantissa.
Except for de-normalized numbers, the mantissa always represents a sum of fractional powers of 2, i.e. 1/2, 1/4, 1/8, 1/16, 1/32, ....
The exponent is an "offset" signed integer where 0...max in the exponent field represents about -max/2...0...max/2
The result of this powers-of-2 format is you cannot divide by powers of 10 and retain exact decimal accuracy for most numbers.
It is easy to multiply by 10 using powers of 2: 10x == x * (8 + 2)
It is NOT easy to divide by 10 using powers of 2:
-- 1/8 is too big. 1/16 is too small.
-- 2 * 1/16 is the same as 1/8, so that doesn't work.
-- 1/16 + 1/32 is too small.
-- 1/16 + 1/32 + 1/64 is too big.
-- 1/16 + 1/32 + 1/128 is too big.
-- 1/16 + 1/32 + 1/256 is too small.
-- 1/16 + 1/32 + 1/256 + 1/512 is too small.
Eventually you realize you have an infinite repeating sequence of bits representing ever-smaller powers of two:
000110011001100110011...
which represents
2-4+2-5+2-8+2-9+2-12+2-13+2-16+2-17+2-20+2-21...
So it is impossible to represent 1/10 in a finite-length set of binary fractions.
While it is trivial to write things like round(x * 1000) / 1000 and think that you have managed to get an answer accurate to precisely 3 decimal digits, in reality you are fooling yourself.
In order to actually get a precise number of digits after a decimal point, you MUST EITHER use a math package supporting a decimal-based number system -- e.g. binary-coded-decimal -- OR use a fixed-point system where everything is stored as integers which are assumed to represent K * 10^n, where n is the number of decimals after the decimal point. For 2 digits precision, everything is stored as *100 values. For 3 digits precision, everything is stored as *1000 values.
Any other approach to "round to n digits after decimal point" will fail to maintain desired accuracy for most real decimal numbers.