Skip to content
Prev 299471 / 398503 Next

number of decimal places in a number?

On Sat, Jul 07, 2012 at 01:12:34PM +0100, Ted Harding wrote:
Hi.

This difference is due to rounding to 15 digits in as.character().
This function rounds to 15 decimal digits, which is the maximum
number of digits, which can always be converted to binary
and back. Function print(, digits=22) prints the decimal
equivalent of the represented number. So, it is more accurate, but
its output may contain digits, which are purely the consequence
of inaccuracy of the representation.

The same output as from print(, digits=17) may be obtained
using

   sprintf("%20.17f", x)

Of course, if the required number of digits is close to 17 or
even more, the last digits are the last digits of the represented
number, not of the intended result of the computation.

Hope this helps.

Petr Savicky.