This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Compare 2 Numbers

Help for those learning Tcl or writing their own scripts.
Post Reply
A
Access
Voice
Posts: 22
Joined: Sun Jun 04, 2006 6:31 am

Compare 2 Numbers

Post by Access »

I have 2 numbers - eg. 2.200.000.000 & 6.210.000
Now i want to know which number is higher - how do i do that? :(
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

use '<' or '>' in if statements
User avatar
Vexor
Voice
Posts: 18
Joined: Fri Jul 21, 2006 4:22 am
Location: Washington Court House
Contact:

Post by Vexor »

Code: Select all

  if { num1 > num2 } {
                 true
     } else {
                 false
     }

"just the usual suggestion, RTFM" --demond
A
Access
Voice
Posts: 22
Joined: Sun Jun 04, 2006 6:31 am

Post by Access »

that dont work :(
whats about the dots in the numbers? thats the reasen that > and < wont work? how to "strip" the dots?
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

if you use multiple dots in a number you'd get an invalid number format, so it won't work... don't use the dots
Z
Zero
Voice
Posts: 4
Joined: Tue Jul 25, 2006 4:17 am

Post by Zero »

Code: Select all

set number1 [string map -nocase {"." ""} "2.200.000.000"]
set number2 [string map -nocase {"." ""} "6.210.000 "]
if {$number1 > $number2} {
true
} else {
false
}
Try this
Post Reply