0 votes
1 view
in R Programming by (5k points)

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

1 Answer

0 votes
by (24.7k points)
edited by

You can use the following functions to keep the trailing zeros while printing a number:

sprintf("%.3f", round(5.2,3))

[1] "5.200"

formatC( round( 5.2, 3 ), format='f', digits=3 )

[1] "5.200"

If you want to learn more about R programming watch this tutorial on Introduction to Data Science with R 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...