mIRC Home    About    Download    Register    News    Help

Print Thread
help with separating a value #239897 02/12/12 04:19 PM
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.

Re: help with separating a value [Re: mehenky] #239898 02/12/12 06:41 PM
Joined: Jul 2006
Posts: 3,715
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,715
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.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: help with separating a value [Re: Wims] #239899 02/12/12 07:48 PM
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.

Re: help with separating a value [Re: mehenky] #239901 02/12/12 11:16 PM
Joined: Dec 2011
Posts: 15
J
JohnEricNO Offline
Pikka bird
Offline
Pikka bird
J
Joined: Dec 2011
Posts: 15
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)

Re: help with separating a value [Re: JohnEricNO] #239907 03/12/12 11:08 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
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
Re: help with separating a value [Re: Riamus2] #239908 03/12/12 01:06 PM
Joined: Jul 2006
Posts: 3,715
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,715
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.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: help with separating a value [Re: Wims] #239909 03/12/12 08:34 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
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
Re: help with separating a value [Re: Riamus2] #239934 05/12/12 08:24 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
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

Re: help with separating a value [Re: hixxy] #239938 06/12/12 03:45 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
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
Re: help with separating a value [Re: mehenky] #240799 28/02/13 01:49 PM
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