|
-
Apr 3rd, 2002, 08:06 AM
#1
Thread Starter
Frenzied Member
something funny
VB Code:
Dim S as Single
Dim S1 as Integer
S = 5.2
S1 = Int(s)
Msgbox S - S1
Something is wrong in my PC or my Math teacher has lied, but i think 5.2 - 5 is 0.2, not 0.199998....
Is this a problem in VB or my Celeron is sucks?
(with Double this problem solved but its..... tricky)
answer please... (urgent)
-
Apr 3rd, 2002, 08:13 AM
#2
Hyperactive Member
WeIrD
What the hell?
The same thing is happening here,,,,
-
Apr 3rd, 2002, 08:14 AM
#3
Thread Starter
Frenzied Member
Really?! ohh no.... (cryin face)
-
Apr 3rd, 2002, 08:20 AM
#4
Addicted Member
Why are you casting in the first place?
-
Apr 3rd, 2002, 08:24 AM
#5
Bouncy Member
its not your celeron, its to do with the way that decimal numbers are stored in memory, not just in VB.
decimal numbers cannot be represented accuratly in binary basically.
do a search on here for "floating-point numbers microsoft" and you'll find a nice big discussion about it - quite interesting actually
-
Apr 3rd, 2002, 08:46 AM
#6
Thread Starter
Frenzied Member
umm i cant found i think 
but what can i do to solve my problem, without change the type of "s"?
help me pls...
-
Apr 3rd, 2002, 08:47 AM
#7
Addicted Member
I learned in school that you can only use so many decimal places as the least number of decimal places. You should round it to 1 decimal place.
VB Code:
Dim S As Single
Dim S1 As Integer
S = 5.2
S1 = Int(S)
MsgBox Round(S - S1, 1)
-
Apr 3rd, 2002, 08:56 AM
#8
Thread Starter
Frenzied Member
This is an amazing tip , ill make a try!
Thanks for the answers.
Jim
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
|