Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello !

I have a very strange problem. Look at this :

 

Dim a, b, c as double
a = 1
b = 0.96

c = a - b
msgbox(c)

 

Why does the msgbox display 0.0399999999999999999 ?????? The result of this simple operation shouldn't be just 0.04 ?

 

Really, I don't understand. And the worst : when b < 0.95, c is correct :confused: :confused:

 

Well, has anybody already had such a problem ?

Thanks!

Posted
It's strange, but it's the same problem...I think I'll cope that with Math.Round or something...even if it's not, let's say, "professional" :D
Posted

I tried your example and my msgbox displayed 0.04, although if you debug the debugger will show 0.0400000000036.

 

I agree its weird, but I do not know why your msgbox didnt display 0.04 ....

Dream as if you'll live forever, live as if you'll die today
  • 3 weeks later...
Posted

Yeah, Decimal.Add/Subtract/Multiply combined with Decimal.Todouble should help.

 

e.g.

Dim a,b,c as double

 

b = 1234.555

c = 0234.554

a = Decimal.ToDouble(Decimal.Subtract(b,c))

 

should give a double of 1000.001

Hamlet

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...