Jump to content
Xtreme .Net Talk

Math.Ceiling gives wrong result!!


Recommended Posts

Posted

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.

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...