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.

is this possible?

Old posts that have not been replied to for several years.
Locked
m
mkluin
Voice
Posts: 27
Joined: Tue Nov 05, 2002 4:11 am

is this possible?

Post by mkluin »

Hi,

I have a script that is used for a online game.

People can use it to calculate money in their bank with the use of interest.

They put the gold in their bank account and also the hours they want to see. for example: "richard calc 7646383 5" where 5 is the hours.

The script i have does work, but has a maximum of 10 digits.

Also when 10 digits is used, it puts a - before the total.

Is there a way to make it so that it calculates people's gold witch are more than 10 digits?

The code is:

Code: Select all


            set gold_start [lindex $arg 1] 
            set gold_hours [lindex $arg 2]                 
       set check 1 
       set gold_make "$gold_start" 
       while {$check != [expr $gold_hours +1]} { 
         set gold_new [expr $gold_make * 0.01] 
         set gold_make [expr int ($gold_make) + $gold_new]               
         set check [incr check] 
       } 
            putserv "PRIVMSG $channel :After $gold_hours hour(s) in the bank, $gold_start gold will be [expr int($gold_make)] gold." 
          } 

Regards mkluin
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Anything's possible! First try using floating point instead of integer. (I.e. get rid of the int() part.) If that doesn't work find a "bignum" package for tcl.
m
mkluin
Voice
Posts: 27
Joined: Tue Nov 05, 2002 4:11 am

Post by mkluin »

I am not that good in tcl so i don't know what you mean with floating point.

any example that you can give me?
Regards,

Mkluin
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Floating point, isn't a Tcl term.

It is used to discribe a type of number.

There are integers, which are whole numbers.

Floating point, which have a decimal point in.
m
mkluin
Voice
Posts: 27
Joined: Tue Nov 05, 2002 4:11 am

Post by mkluin »

i still don't understand how to get it to work that way.

how does it work, or where do i have to put it.

i don't know scripting at all.
Regards,

Mkluin
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Basically,

set gold_make [expr int ($gold_make) + $gold_new]

should be

set gold_make [expr $gold_make + $gold_new]

You'll have decimal points in your answer though! If you want to get rid of them, use something like:

regexp {^([^\.]*)} $gold_make x intpart

now $intpart is the gold with no decimal point. Hope it helps!

Oh ya, the big difference between floating point and integer is that floating point can have decimals.. but the *other* big difference is that floating point numbers can be huge, much much bigger than integers. As you can see with this example:

% set x 10000000000000
10000000000000
% expr $x
integer value too large to represent
% set x 10000000000000.0
10000000000000.0
% expr $x
1e+13
m
mkluin
Voice
Posts: 27
Joined: Tue Nov 05, 2002 4:11 am

Post by mkluin »

Ok i got that to work. Thanks for your help
Regards,

Mkluin
Locked