Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (5.3k points)

I would like to keep trailing zeros, for example, if I type:

round(5.2, 3)

I would like the output to be:


1 Answer

0 votes

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 

Browse Categories