[R] how to calculate a numeric's digits count?

S Ellison S.Ellison at LGCGroup.com
Fri Oct 24 11:50:55 CEST 2014


Dear Po Su,

All floating point numbers in R have exactly the same number of binary digits (53) and therefore the same number of decimal digits (15.95, as decimals aren't represented exactly in binary). If you want to find out how many decimal digits are after the decimal point, you could try subtracting floor(log10(x)) from 16.
Anything else is pretty much futile - to the point of nonsensical. You can never have exact representation of all decimal fractions in a binary computer, and once you understand that you can see that the number of decimal digits you get from any character representation depends only on how much you decide to round when converting to character format. That is essentially arbitrary, so any games you play with conversion to character are just telling you how many digits you decided to round each number to, not how many there were to start with.


S Ellison




*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list