Home >>VB.Net Programs >VB.Net program to truncate the value of the floating-point number
Here, using the Truncate() method of Math class, we can truncate the value of a floating-point number and print the result on the console screen.
Program :
Below is the source code for truncating the floating-point number value. The program given is compiled and successfully executed.
Example
Module Module1
Sub Main()
Dim X As Decimal = 3.26
Dim Y As Decimal = 0
num2 = Math.Truncate(X)
Console.WriteLine("Truncated value: {0}", Y)
End Sub
End Module
Explanation:
We created a Module1 module in the program above that contains the Main() method. We created two local variables X, Y in the Main() method that are initialized with 3.26 and 0 respectively.
num2 = Math.Truncate(X) Console.WriteLine("Truncated value: {0}", Y)
Here, we used the Math Class Truncate() method. The Truncate() method truncates the value of variable X and assigns it to variable Y, and then displays the value of variable Y on the screen of the console.