In R, How can I ensure that i only print 3 characters/numbers after the decimal point? I thought that format command with nsmall parameter is sufficient but i am not getting required answer
> format(0.6791787, nsmall=3)
[1] "0.6791787"
I want 0.679
Using sprintf
it would be
sprintf("%.3f", 0.6791787)
# [1] "0.679"
The number after the .
and before the f
is the number of digits to print after the decimal.
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