Ad space (banner)
๐Ÿ“ŠR Lessons
Lesson 45 / 68

Rounding numbers (floor, ceiling, round)

This lesson covers rounding decimals in R, with the aim of choosing the right method for the purpose.

floor() rounds down, ceiling() rounds up, and round() rounds to nearest (in R's own particular way). Picture shaving down, bumping up, and snapping to whichever is closer.

The sample code shows that similar-looking decimals give different results depending on the function: floor(3.7) is 3, ceiling(3.2) is 4, and round(3.5) is 4.

A common early stumble is that round() is not simple round-half-up. R's round() defaults to banker's rounding, which snaps a half to the nearest even number, so the result may not be what you expected.

In professional work, the choice matters — rounding in statistical work, aligning decimal places for display — because the result changes with it.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run R directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)