Home »
        VB.Net »
        VB.Net Programs
    
    VB.Net program to round off the value of the floating-point number
    
    
    
    
	    
		    By Nidhi Last Updated : November 16, 2024
	    
    
    
    Rounding off the value of the floating-point number
    Here, we will round off a decimal floating-point value using the Round() method of Math class, which will return value after rounding off the floating-point value.
    VB.Net code to round off the value of the floating-point number
    The source code to round off the value of the floating-point number is given below. The given program is compiled and executed successfully.
'VB.Net program to round off a 
'floating-point value.
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
Output:
num1: 3.26
num2: 3
Press any key to continue . . .
    Explanation:
    In the above program, we created a module Module1 that contains the Main() method. In the Main() method we created two local variables num1, num2 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 Round() method of Math class. The Round() method will round off the value of variable num1 and assigned to the variable num2.
    VB.Net Basic Programs »
    
    
    
    
   
    
  
    Advertisement
    
    
    
  
  
    Advertisement