Reputation: 1
I am working on a program and the only problem i am facing is that a decimal like 2.6 is being rounded off to 3 or any other number like 1.7 is being rounded off to 2. How can I make it to round 1.6 off to just 1?
Any help will really be appreciated. Thanks in advance.
Upvotes: 0
Views: 4336
Reputation: 56509
You are looking for Math.Floor Method (Double) as of from .NET Framework 2.0
Examples:
Floor(2.10) = 2
Floor(2.00) = 2
Floor(1.90) = 1
Floor(1.80) = 1
Floor(1.70) = 1
Floor(1.60) = 1
Floor(1.50) = 1
Floor(1.40) = 1
Floor(1.30) = 1
Floor(1.20) = 1
Floor(1.10) = 1
Floor(1.00) = 1
Upvotes: 1
Reputation: 17630
That feature is called "Truncate". There's a Math.truncate()
function. From the docs:
Dim decimalNumber As Decimal
decimalNumber = 32.7865d
' Displays 32
Console.WriteLine(Math.Truncate(decimalNumber))
decimalNumber = -32.9012d
' Displays -32
Console.WriteLine(Math.Truncate(decimalNumber))
Upvotes: 3