20.12453
to
20.1?
or 20.12
more generally how do you specify number of decimals when rounding?
bob = roundn(20.12453,-1)
gives:
20.1000
but how do I delete the trailing zeros?
>How do I round this number:
>20.12453
>to
>20.1?
>or 20.12
You cannot. There is no exact binary floating point representation
for 20.1 or 20.12, so no matter what you do, you will not be able
to round to exactly the target value. For numbers in the range of 20.1
the closest you can get will be off by about 2^(-49).
If you need to limit the number of decimal places for string output
purposes, then you can use an output format such as %.2f
--
"Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us." -- Ecclesiastes