Rounding output. Consider the Double 1.234. When we call the Math.Round function on it, we receive the number 1—the fractional part was rounded down.
Math.Round input, output:
Example. This program calls Math.Round on the Double 123.45. To call Math.Round With no options, we use just one argument. This rounds the number to 123.
And With a second argument of 1, we round to one decimal place. This yields the values 123.5 (for AwayFromZero) and 123.4 (for ToEven).
AwayFromZero With a positive number, this option will round up—so 123.45 becomes 123.5.
ToEven This will round to an even number—so 123.45 becomes 123.4 because 4 is an even number and 5 is not.
' Call Math.Round on this Double.
Dim before As Double = 123.45
Dim after1 As Double = Math.Round(before, 1, MidpointRounding.AwayFromZero)
Dim after2 As Double = Math.Round(before, 1, MidpointRounding.ToEven)
Dim after3 As Double = Math.Round(before)
' Use on this Decimal.
Dim before2 As Decimal = 125.101
Dim after4 As Decimal = Math.Round(before2)
Dim after5 As Decimal = Math.Round(before2, 1)
Notes, program. We also use Math.Round on the Decimal type. These have the same results as the Double type. The Math Class supports many numeric types, including Double and Decimal and others.