Math.Ceiling gives wrong result!!

  • Thread starter Thread starter Cheung
  • Start date Start date
C

Cheung

Guest
Dim result As Double
Dim first As Double
Dim second As Double
Dim third As Double
Dim fourth As Double
first = 31
second = 13
third = 31
fourth = 434
result = Math.Ceiling((first - second) / third * 434)
MsgBox("result" & result)

Obviously, the correct answer is 252. But it gives 253!! pls suggest how I can solve it. it is a matter of the datatype?

Thank you very much.
 
Actually, it computes to 252.00000000000003, which when using
Ceiling rounds up to 253. If you're looking to round a number,
use Math.Round.

Also, get into the .NET habit of using MessageBox.Show instead
of MsgBox.
 
Back
Top