How to Keep Trailing Zeros After Rounding in R (Example Code)
In this post you’ll learn how to retain zeros at the end of a number after rounding in R programming.
Introducing Example Data
my_data <- 5.55 # Example data my_data # [1] 5.55 |
my_data <- 5.55 # Example data my_data # [1] 5.55
round(my_data, 5) # Rounding removes zeros # [1] 5.55 |
round(my_data, 5) # Rounding removes zeros # [1] 5.55
Example: How to Keep Trailing Zeros Using the sprintf() Function
sprintf("%.5f", round(my_data, 5)) # Applying sprintf # [1] "5.55000" |
sprintf("%.5f", round(my_data, 5)) # Applying sprintf # [1] "5.55000"