I would like to keep trailing zeros, for example, if I type:
round(5.2, 3)
I would like the output to be:
5.200
Use the pound sign to prevent extra zeroes. The symbol # is another placeholder character in custom formats. This will prevent all leading zeroes if used at the front of the number, and prevent all trailing zeroes if used after the decimal point. For example, the custom format 00.
For example, in pharmacy, trailing zeros are omitted from dose values to prevent misreading. However, trailing zeros may be useful for indicating the number of significant figures, for example in a measurement. In such a context, "simplifying" a number by removing trailing zeros would be incorrect.
1) Leading zeroes shall be suppressed, although a single zero before a decimal point is allowed. 2) Significant zeroes shall not be suppressed; when a single zero is significant, it may be used. 3) Do not include Trailing zeroes after the decimal point unless they are needed to indicate precision.
Get to the Format Cells dialog (e.g. by right-clicking a cell and selecting "Format Cells...") On the Number tab, select Number from the list of Categories. Set the Decimal Places box to 6. Hit Ok .
If this is for printing purposes, sprintf
is what you are after:
> sprintf("%.3f", round(5.2,3)) [1] "5.200"
See ?sprintf
for formatting details.
When you print it out, you should be able to do:
formatC( round( 5.2, 3 ), format='f', digits=3 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With