×

VB.Net Programs

VB.Net program to truncate the value of the floating-point number

By Nidhi Last Updated : November 16, 2024

Truncating floating-point number

Here, we will truncate the value of a floating-point number using the Truncate() method of Math class, and print the result on the console screen.

VB.Net code to truncate the value of the floating-point number

The source code to truncate the value of the floating-point number is given below. The given program is compiled and executed successfully.

'VB.Net program to truncate the floating-point number.

Module Module1

    Sub Main()
        Dim num1 As Decimal = 3.26
        Dim num2 As Decimal = 0

        num2 = Math.Truncate(num1)

        Console.WriteLine("Truncated value: {0}", num2)
    End Sub

End Module

Output:

Truncated value: 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.Truncate(num1)
Console.WriteLine("Truncated value: {0}", num2)

Here, we used the Truncate() method of Math class. The Truncate() method will truncate the value of variable num1 and assigned to the variable num2, and then we printed the value of num2 on the console screen.

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.