Home >>VB.Net Programs >VB.Net program to round off the value of the floating-point number
Here, we round off a floating-point decimal value using the Math Class Round() method, which returns the value after rounding off the floating-point value.
Program :
The source code to round off the floating-point number value is given below. The program given is compiled and successfully executed.
Example
Module Module1
Sub Main()
Dim num1 As Decimal = 3.26
Dim num2 As Decimal = 0
num2 = Math.Round(num1)
Console.WriteLine("num1: {0}", num1)
Console.WriteLine("num2: {0}", num2)
End Sub
End Module
Explanation:
We generated a Module1 module in the program above that contains the Main() method. We created two local variables num1, num2 in the Main() method that are initialized with 3.26 and 0 respectively.
num2 = Math.Round(num1) Console.WriteLine("num1: {0}", num1) Console.WriteLine("num2: {0}", num2)
Here, we used the Math Class Round() method. The value of variable num1 is round off by the Round() method and assigned to variable num2.