|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: Mon Nov 11, 2002 1:58 am
More effective variable. |
I have a variable I use to break down large numbers into smaller ones. For instance, 1230000 reads as 1.23M. This is the script I have for it:
#var denomination {%if( %format( 0, %1) >= 1000000000, %format( 2, %eval( %float( %1) / 1000000000))G)%if( %format( 0, %1) >= 1000000 AND %format( 0, %1) < 1000000000, %format( 2, %eval( %float( %1) / 1000000))M)%if( %format( 0, %1) >= 1000 AND %format( 0, %1) < 1000000, %format( 0, %eval( %float( %1) / 1000))K)%if( %format( 0, %1) < 1000, %1)}
To break down the large number -> @denomination(@large_number)
This fires three times every time the MUD sends my prompt, which is pretty often, and it bogs me down considerably. I was wondering if there was a more efficient way of doing this. Much of my settings depends on these three firing constantly, but the lag they create is counter-productive to my char's health.
Any ideas?
Fat Tony |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Nov 11, 2002 2:27 am |
Try using %format("&1.4G",%1)
You would have to decide how many significant digits to keep. Also since it uses scientific notation it would be easy to seperate the parts and shift the decimal portion to work off the K/M/G notation by use of a #CASE or %case. If you wish to keep that notation, I would reccommend that you figure a way to convert the function to an alias first so that you can use #CASE and an intermediate variable. |
|
|
|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: Mon Nov 11, 2002 3:17 am |
Hmm... I tried a few instances of this, but its still got me stumped. %format("&1.4G",@large_number) returns something like 6.703E6. If you have a moment, could you give me an example? I'll disect it and work from there.
Thank you for your time.
Fat Tony |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Nov 11, 2002 4:27 am |
You can replace all the "%format( 0, %1)" with "%1", that should save some of the processing. %float doesn't exist in the public version, so I've also dropped that. It looks like this is just for display purposes, so you probably meant to use #FUNCTION instead of #VAR. You might need to use %eval, I've done it both ways.
#FUN denomination {%if(%1 >= 1000000000, (%1/1000000000).((%11000000000)/10000000)G, %if(%1 >= 1000000, %eval(%1/1000000).%eval((%11000000)/10000)M, %if(%1 >= 1000, %eval(%1/1000).%eval((%11000)/10)K, %1)))}
Note: Be sure to count my () and {}, I almost always mess them up when I do stuff like this.
LightBulb
Senior Member |
|
|
|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: Mon Nov 11, 2002 6:05 am |
Worked just fine, and it is much faster now. Thank you both.
Fat Tony |
|
|
|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: Mon Nov 11, 2002 6:42 am |
Posted that before fully testing it, came up with one problem. When a number's second place is a 0, it drops it.
Ex-
#show @denomination( 1053356)
returns
1.5M
Any way to fix this?
Fat Tony |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Nov 11, 2002 7:16 pm |
Since you have %float, that should be fairly easy. Leading zeros are difficult (not impossible) with the public version {something like %if(@x < 10, "0"@x, @x)}.
#FUN denomination {%if(%1 >= 1000000000, %format(2, %float(%1/1000000000))G, %if(%1 >= 1000000, %format(2, %float(%1/1000000))M, %if(%1 >= 1000, %format(2, %float(%1/1000))K, %1)))}
LightBulb
Senior Member |
|
|
|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: Mon Nov 11, 2002 8:23 pm |
hehe well that took care of the 1.5M problem. Now it just returns 1.00M. Should I put the %eval's back in, my attempts with that have been unsuccessful.
Fat Tony |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Nov 12, 2002 12:33 am |
I thought you would be able to figure how to put it together. It is not the fastest form since you seem intent on having built as a function.
#FUN ConvertSci {%concat(%left(%concat(%1,"000000"),%eval(%mod(%2,3)+1)),".",%right(%1,%eval(%mod(%2,3)+1)))%case(%eval((%2/3)+1),%null,K,M,G,T)}
#FUN Denomination {@ConvertSci(%word(%remove(".",%replace(%format("&1.6G",%1),"E"," ")),1),%word(%remove(".",%replace(%format("&1.6G",%1),"E"," ")),2))} |
|
|
|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: Tue Nov 12, 2002 7:19 pm |
That does work, but it is essentially the same thing as my original form. I'm not stuck on using #FUN, I just want the a faster way to do it, if there is one available. If I missed your point, Vijilante, I apologize, but if you or anyone has a faster process that would speed me up a little, I'd appreciate the input.
Thank you for your time.
Fat Tony |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue Nov 12, 2002 8:51 pm |
If you really want to speed it up, just drop the part after the decimal point. Another possibility is to use only 1 digit following the decimal point -- this avoids the problem of leading zeros not being displayed.
LightBulb
Senior Member |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Nov 12, 2002 11:51 pm |
Since you not stuck on a function we condense repetive calculations into variables, and then gain some speed by only accessing the variable. What I wrote is faster then what you had, but this will be even faster.
#VAR Denomination {}
#ALIAS Denominate {Denomination=(%remove(".",%replace(%format("&1.6G",%1),"E"," "));#MATH TempDenom %mod(%word(@Denomination,2),3)+1;Denomination=%word(@Denomination,1);Denomination=%concat(%left(%concat(@Denomination,"000000"),@TempDenom),".",%right(%1,@TempDenom),%case(@TempDenom,%null,K,M,G,T))}
Assuming I have my parenthesis correct you call Denominate with the value and retrieve the result from @Denomination. Now read my first post again...an alias, a temp variable, and %case. |
|
|
|
fattony Apprentice
Joined: 27 Dec 2001 Posts: 105 Location: USA
|
Posted: Sun Nov 17, 2002 12:03 am |
This still just returns the number with a decimal after the first place.
Ex-
1494500 now becomes 1.494500
I'm trying to make it 1.49M
Am I missing something?
Fat Tony |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|