|
-
Apr 11th, 2005, 06:07 AM
#1
Thread Starter
Frenzied Member
Re: select case with non integer numbers
this is interesting
the following structure works
Code:
powstring = power
Select Case powstring
Case "0.001"
'statements
case 1
'statements
case "60.001"
'statements
end select
but not this code
Code:
powstring = power
Select Case powstring
Case 0.001
'statements
case 1
'statements
case 60.001
'statements
end select
-
Apr 11th, 2005, 06:12 AM
#2
Re: select case with non integer numbers
 Originally Posted by vb_student
this is interesting
the following structure works
Code:
powstring = power
Select Case powstring
Case "0.001"
'statements
case 1
'statements
case "60.001"
'statements
end select
but not this code
Code:
powstring = power
Select Case powstring
Case 0.001
'statements
case 1
'statements
case 60.001
'statements
end select
Floating point (single and double) are evil.
You just fell right into the reason for it.
DISPLAY a DOUBLE value and you see one thing - compare it in an IF or SELECT/CASE and it all of a sudden doesn't work.
Something that might display at 4.5 is really stored as 4.499999999999999999
That's the way DOUBLE works.
Why can't you use CURRENCY? It doesn't have this problem and the SELECT/CASE will all of a suddent work beautifully.
If you need double, change the CASE's to a RANGE - not an exact value - a bit below and a bit above the value you are trying to CASE on.
-
Apr 12th, 2005, 05:58 AM
#3
Thread Starter
Frenzied Member
Re: select case with non integer numbers
hey in another part of my code, power with 0.001 works OK
is this some sort of idiosynchracy in VB?
i had nto decalred the power in that module too. is it because of that, in the module where it was not working i had dxeclared it as a double.
-
Apr 12th, 2005, 06:01 AM
#4
Re: select case with non integer numbers
You must understand that DOUBLE will give you these inconsistent results.
Do you need to store your values as DOUBLE?
Why doesn't the CURRENCY datatype work for you - it precise and doesn't have the issues that DOUBLE does.
-
Apr 14th, 2005, 04:30 AM
#5
Thread Starter
Frenzied Member
Re: select case with non integer numbers
it somehow works now with double, i will leave it at that and if the big guy wants me to clean up the code, i will do it later
what is the difference between double and currency?
currency sounds something to do with dollars, pounds and yen not fractional numbers.
-
Apr 14th, 2005, 05:45 AM
#6
Re: select case with non integer numbers
Currency is a datatype that allows four digits after the decimal point.
It's actually a long, with an "implied" decimal - so it has the accuracy of long but the fake decimal point works for you...
-
Apr 14th, 2005, 09:20 AM
#7
Thread Starter
Frenzied Member
Re: select case with non integer numbers
thanks for telling me about currencies
i just tried longs elsewhere in my code and they did not work for fractions
there does not seem to be a correspondence between variable types in c and VB
doubles and longs used to accept fractional parts in c but they dont in VB, correct?
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
|