How do you round a Double down to the nearest integer in VB .NET?
Question
How do you round a Double down to the nearest integer in VB .NET?
Solution
This is pretty old, but the accepted answer of using Math.Truncate
is technically incorrect: Truncate rounds towards zero, not down. For example, -1.5 is rounded to -1 instead of -2.
In order to always round down, use Math.Floor
.
OTHER TIPS
Are we talking VB.NET or VB6? In VB.NET use Math.Truncate.
dim d as decimal = 1.50
dim I as int64 = convert.toint64(D)
This is the logic We have used
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow