|
-
Aug 19th, 2002, 09:12 PM
#1
Thread Starter
Member
Why is this false?
If I use this code it comes out false. Why?
(0.0087 * 100) = 0.87
If I encapsulate each side of the equation with Val() it comes out true.
Is it something to do with a floating decimal point?
Help
-
Aug 19th, 2002, 09:15 PM
#2
Thread Starter
Member
oh and ..
For the record the following code comes out true,
(0.0077 * 100) = 0.77
Why is this?
-
Aug 19th, 2002, 09:17 PM
#3
Need-a-life Member
I guess it might be because the 0.87 is being represented as a single, and the multiplication returns a double. As a matter of fact, if you do this, you get true:
VB Code:
CSng(0.0087 * 100) = 0.87
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 19th, 2002, 09:20 PM
#4
-
Aug 19th, 2002, 09:21 PM
#5
Need-a-life Member
As well... you'll get True with this code:
VB Code:
CSng(0.0087) * 100 = 0.87
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 19th, 2002, 09:35 PM
#6
Thread Starter
Member
Well what about this?
Actually if you try this, you can avoid all confusion about data types and still get a false.
Private Sub Command1_Click()
Dim dblNumber1 As Double
Dim dblNumber2 As Double
dblNumber1 = 0.87
dblNumber2 = 0.0087 * 100
Debug.Print "========================================"
Debug.Print "dblNumber1 = " & dblNumber1
Debug.Print "dblNumber2 = " & dblNumber2
Debug.Print "dblNumber1 = dblNumber2: " & (dblNumber1 = dblNumber2)
End Sub
It is pretty weird
-
Aug 19th, 2002, 10:15 PM
#7
Need-a-life Member
Maybe the different mantissa is the problem. Check this out:
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim dblNumber1 As Double
Dim dblNumber2 As Double
dblNumber1 = 0.87
dblNumber2 = CSng(0.0087) * 100
Debug.Print "========================================"
Debug.Print "dblNumber1 = " & dblNumber1
Debug.Print "dblNumber2 = " & dblNumber2
Debug.Print "dblNumber1 = dblNumber2: " & (dblNumber1 = dblNumber2)
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Aug 19th, 2002, 10:18 PM
#8
Get this:
Call MsgBox((8.7 * 10 ^ -3 * 100) = 0.87)
is true...
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Aug 19th, 2002, 10:33 PM
#9
-
Aug 19th, 2002, 10:34 PM
#10
I figured as much, but this is something I would classify as a quirk, not a feature...
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Aug 19th, 2002, 10:56 PM
#11
Hyperactive Member
ok...let me see this...
Why?...why would you like to COMPARE a Math operation with it's actual result?
and being 0.87 the actual result of (0.0087 * 100) ...It'll of course will give you a TRUE result...
because [B]You are comparing one VALUE against another VALUE
Isn't obvious that this (0.0087 * 100) = 0.87 is not an Math operation?, but a tricky question...
"Who Dares Wins" - "Quien se Arriesga Gana"
Mail me at: 
-
Aug 19th, 2002, 11:00 PM
#12
Thread Starter
Member
OK McBrain you've earned you name, that makes sense.
I looked up some information about Mantissas and indeed that appears to be the answer.
dblNumber1 and dblNumber2's exponent and the mantissa are different, though they represent the same number. That is why Val() works and a simple = does not.
I hope everyone at NASA is aware of this.
Thanks
-
Aug 19th, 2002, 11:03 PM
#13
Hyperactive Member
err...actually
rereading...it's the representation of a Math statement...
just like 1 = 1 that of course it's TRUE!!
"Who Dares Wins" - "Quien se Arriesga Gana"
Mail me at: 
-
Aug 19th, 2002, 11:10 PM
#14
Frenzied Member
Microsoft tells not to compare floating point values for the equality... because it loses some precision when you display a floating point in limited digits..i.e.
0.87 might be 0.8700000000121111 for the registers but it displays to be 0.87
-
Aug 19th, 2002, 11:29 PM
#15
Need-a-life Member
Originally posted by jhunt
OK McBrain you've earned you name, that makes sense.
I looked up some information about Mantissas and indeed that appears to be the answer.
dblNumber1 and dblNumber2's exponent and the mantissa are different, though they represent the same number. That is why Val() works and a simple = does not.
I hope everyone at NASA is aware of this.
Thanks
You're welcome.... and I also hope NASA is aware of it.
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|