mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2012
Posts: 9
M
mehenky Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2012
Posts: 9
im new to the mirc scripting stuff. i need some help with separating a random value.

for example; after a calculation. var %money = { $calc(54 * 2154 ) }

%money = 116316

now the output of the $calc function should be separeted by a comma every 3 digits. starting from the back.

so it would look like this: $ 116,316 or if the output was larger $ 1,116,316

searched on the web but couldn't find a suitable awnser.

Joined: Jul 2006
Posts: 4,156
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,156
Look at /help $bytes wink
Note also that you are using { } incorrectly here, it works because of the way the mirc's parser works but it's incorrect, I suggest you also look at /help /var, you can see the syntax doesn't use { } at all.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2012
Posts: 9
M
mehenky Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2012
Posts: 9
thanks for the quick replay. gonna check it out smile

tought it was with {}. thanks for the tip.

Joined: Dec 2011
Posts: 18
J
Pikka bird
Offline
Pikka bird
J
Joined: Dec 2011
Posts: 18
create a $comma function:

alias comma {
var %a, %b = $regsub($ticks,$$1,/\G([+-]?\d+?)(?=(?:\d{3})++(?=\.\d++$|$))/g,\1 $+ $chr(44),%a)
return %a
}

To use: var %money = $comma(1234567890)

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
There isn't any need to make a comma identifier. As mentioned above, $bytes() will do this for you.

Code:
var %money = $bytes(1234567890,b)


Regardless how you do this, always keep in mind that if your number gets too large, it will cause an error. So if you're making a game where you are giving huge amounts of money, you may want to reconsider and give less money.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 4,156
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,156
How using a large number will cause an error exactly? At best he will get a loss of precision, perhaps that is what you meant to say.

I should also point out that the regex version won't cause any loss in precision, which should also be the case for $bytes in this case, imo.
I'm guessing $bytes has been implemented in a generic way that create a loss in precision even when it could be avoided, but it sounds like a bug in $bytes.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
In regards to being too large for a 32bit app to handle. No, that isn't an actual error message, but it will cause errors in what you're trying to display. "Loss of precision" or "error"... it's still a problem.

Example:

Input:
//echo -a $bytes(123456789123456789123456789,b)
Output:
123,456,789,123,456,790,000,000,000

For basic uses, it works very well. But I've seen people write games where the "money" they give out is in the millions for a given task and that adds up very quickly which is why I mentioned it.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Originally Posted By: Riamus2
There isn't any need to make a comma identifier. As mentioned above, $bytes() will do this for you.

Code:
var %money = $bytes(1234567890,b)


Regardless how you do this, always keep in mind that if your number gets too large, it will cause an error. So if you're making a game where you are giving huge amounts of money, you may want to reconsider and give less money.


You said that there's no need to make a comma identifier and then went on to give a reason why you should create one :p

JohnEricNO's $comma will support larger numbers and it also supports decimal points; two features that $bytes doesn't have. smile

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
True, though the examples given by the OP don't use decimals and the numbers will likely be plenty small for $bytes(). I haven't benchmarked the two, but I'd imagine $bytes() is faster. Though for a single use here or there, the speed won't really make any difference.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2012
Posts: 9
M
mehenky Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Dec 2012
Posts: 9
thanks for al the posts.

fixed it with the $bytes function


Link Copied to Clipboard