Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 45 / 68

Rounding numbers (Floor, Ceiling, Round)

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

Math.Floor() discards everything after the decimal point, Math.Ceiling() rounds up, and Math.Round() rounds to nearest (strictly, to even). Understanding that the right method depends on the purpose matters.

The sample code shows that similar-looking decimals give different results depending on the method: Math.Floor(3.7) is 3, Math.Ceiling(3.2) is 4, and Math.Round(3.5) is 4.

A common early stumble is that Math.Round() is not simple round-half-up. VB.NET's Math.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 directly affects the accuracy of a result — rounding in a monetary calculation, aligning decimal places for display — so it deserves care.

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

๐Ÿงช This site can't compile or run VB.NET 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)