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.
Old posts that have not been replied to for several years.
arcane
Master
Posts: 280 Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:
Post
by arcane » Fri Feb 21, 2003 11:38 am
hi
ive got this simple script
Code: Select all
bind pub - "=" calc_calc
proc calc_calc {nick userhost hand chan arg} {
puthelp "PRIVMSG $chan :[expr $arg]"
}
but if a user types "= 3/2", the result is "1" because expr calculates integers. how can i tell expr to ALWAYS use doubles? result should be "1.5". ill have to change $arg, havent i?
Papillon
Owner
Posts: 724 Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no
Post
by Papillon » Fri Feb 21, 2003 11:42 am
yes you do
Elen sila lúmenn' omentielvo
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Fri Feb 21, 2003 12:38 pm
It should type:"3 / 2"
Once the game is over, the king and the pawn go back in the same box.
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Fri Feb 21, 2003 3:17 pm
Just put "1.0 *' at the beginning of the expr and it'll always be double.
% expr "1.0 * 3/2"
1.5
arcane
Master
Posts: 280 Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:
Post
by arcane » Sat Feb 22, 2003 6:47 am
Code: Select all
puthelp "PRIVMSG $chan :[expr (1.0 * ($arg))]"
"= 3/2":
it just puts "1.0"...
but doesnt really matter. was just a test.
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Sat Feb 22, 2003 7:12 am
You must have put parenthesis around the integer part. Expr follows order of operations. All you have to do is:
puthelp "PRIVMSG $chan :[expr 1.0 * $arg]"
You could also do a regsub which adds a .0 to all integers in the expression.
But if you are using $arg as input from a user, be careful, because expr will evaluate commands in brackets.
e.g.
% set arg {3 + [hello]}
3 + [hello]
% expr $arg
invalid command name "hello"