ADVERTISEMENT
ADVERTISEMENT

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

Here, we are going to learn how to truncate the value of the floating-point number in VB.Net?
Submitted by Nidhi, on December 02, 2020

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.

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.