Skip to content
Prev 79392 / 398502 Next

Automatic rounding of values after factors , converted to numeric, are multipled by a real number

"Nelson, Gary (FWE)" <Gary.Nelson at state.ma.us> writes:
It's all in the conventions. The digits in print() and friends are
significant digits, so we first round to that many significant digits,
then discard trailing zeros, which is why
[1] 12.5
[1] 12.50001

The exception is that we do not discard significant digits to the left
of the decimal point, unless we are using scientific notation
[1] 1.2e+07
[1] 12345678

(the "scipen" options controls the logic for switching notation).

For finer control we have the formatC function:
[1] "1234.00001"
[1] "1234"
[1] "1234.00001"
[1] "1234.0000"