Greater Number

1. Senior Member
Join Date
Dec 1969
Posts
626

## Greater Number

I&#039;m having trouble detecting which number is greater.<BR><BR>All I want to say is:<BR>If value01 &#062; value02 then<BR>response.write(Value01)<BR>else<BR>respons e.write(Value02)<BR>end if<BR><BR>If the value01 is 1 and value02 is 10 then it chooses correctly.<BR>However, if value01 is 2 or greater, it selects value01 (being 2,3,4,5,6,7,8,9) over value02, (being 10)<BR><BR>how do I correct this?<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## No, greater *STRING*...

The things you are comparing, value01 and value02, are *STRINGS*. And the behavior you are seeing is correct for strings.<BR><BR>After all, "aaaaaa" is less than "b", so of course "1111111" is less than "2". <BR><BR>If you want to compare them as *numbers*, then convert them to numbers:<BR><BR>value01 = CDBL( value01 )<BR>value02 = CDBL( value02 )<BR>If value01 &#062; value02 Then<BR>...<BR><BR>

3. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## CDbl() the values.

If CDbl(Value01) &#062; CDbl(Value02) Then

4. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: Greater Number

do <BR><BR>IF CLNG(value01) &#062; CLNG(Value02) THEN<BR><BR><BR>My guess is your numbers are seen as Text, and in that case 2 if greater than 10. By using CLNG you force a conversion to a number.

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## Both slower and...

...no explanation of why.<BR><BR>I dunno, is God going to the Dogs?<BR><BR>

6. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## I leave that for him to learn.

And, in my perfect little world, they do.<BR><BR>:)

7. Senior Member
Join Date
Dec 1969
Posts
626

## Yea, that

solves it..<BR><BR>Thanks Guys

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## As a minor comment on that...

CLNG only properly handles number that are in the range of plus or minus two billion (roughly).<BR><BR>If you are grabbing data off some form and the idiot user types in (say) a telphone number (444 666 1818) where you were asking for a zip code (98122), then CLNG will toss its cookies trying to convert the out of range number.<BR><BR>To play it safe, you probably want to do:<BR><BR> If isNumeric(value01) Then value01=CDBL(value01) Else value01=-1<BR><BR>(-1 is arbitrary, choose an out-of-range number on purpose)<BR>*THEN* you can check for the number being in range:<BR><BR> If value01 &#060; 0 OR value01 &#062; 99999999 OR Int(value01)&#060;&#062;value01 Then<BR> Response.Write "Bad value"<BR> ...<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
7,686

## yeah yeah

I know <BR><BR>To be honest, first I typed CINT, am I glad I changed that ;-)

10. Senior Member
Join Date
Dec 1969
Posts
626

## RE: Greater Number

If your dealing with money specifically.<BR><BR>Such as 10.50 &#062; 10.00.<BR><BR>Which snytax is better...<BR>Cint<BR>Clng

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•