How to round numbers in R
· 1 min read · Updated March 15, 2026 · beginner
r rounding numbers
Rounding Functions and Examples
round(3.14159, 2) # 3.14 - round to 2 digits
ceiling(3.14) # 4 - always round up
floor(3.99) # 3 - always round down
trunc(3.99) # 3 - drop fractional part
Apply to a data frame column:
df <- data.frame(price = c(10.456, 20.999, 15.5))
df$price <- round(df$price, 2)
# price
# 1 10.46
# 2 21.00
# 3 15.50
Note: R uses “round half to even”, so 2.5 rounds to 2.
See Also
- round() — Round to specified digits
- floor() / ceiling() — Round down or up