mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 1,541
L
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Dec 2002
Posts: 1,541
So, I've never been good with this kind of thing, even though this request is fairly simple for others. What Im looking for is a script that separates a number into hundreds, thousands, millions, etc So:

100 = 100
1000 = 1,000
1000000 = 1,000,000

I wasn't sure what language to use to search for this on the forums, or else I would have searched first. Your help if greatly appreciated.


Those who fail history are doomed to repeat it
Joined: Dec 2011
Posts: 18
J
Pikka bird
Offline
Pikka bird
J
Joined: Dec 2011
Posts: 18
Use the $bytes identifer with the bd option.
b keeps bytes so it doesn't divide by 1000 or 1024
d keep the decimal part

example: 100000000.345

//echo $bytes(100000000.345,bd)
answer: 100,000,000.345

Joined: Jan 2012
Posts: 302
Pan-dimensional mouse
Offline
Pan-dimensional mouse
Joined: Jan 2012
Posts: 302
The simplest thing - is to create your own identifier that will take a number and return it with the necessary commas.
I made it very simple, although it can probably be done in an even more tricky way.

So you can try using this script code:
Code
alias numsep {
  if ($len($1) == 4) return $+($mid($1,1,1),$chr(44),$mid($1,2,3))
  if ($len($1) == 5) return $+($mid($1,1,2),$chr(44),$mid($1,3,3))
  if ($len($1) == 6) return $+($mid($1,1,3),$chr(44),$mid($1,4,3))
  if ($len($1) == 7) return $+($mid($1,1,1),$chr(44),$mid($1,2,3),$chr(44),$mid($1,5,3))
  if ($len($1) == 8) return $+($mid($1,1,2),$chr(44),$mid($1,3,3),$chr(44),$mid($1,6,3))
  if ($len($1) == 9) return $+($mid($1,1,3),$chr(44),$mid($1,4,3),$chr(44),$mid($1,7,3))
  if ($len($1) == 10) return $+($mid($1,1,1),$chr(44),$mid($1,2,3),$chr(44),$mid($1,5,3),$chr(44),$mid($1,8,3))
  return $1
}

To test, enter this command: //echo -a $numsep(1000)


Test results:
Quote
100 = 100
1000 = 1,000
10000 = 10,000
100000 = 100,000
1000000 = 1,000,000
10000000 = 10,000,000
100000000 = 100,000,000
1000000000 = 1,000,000,000


🌐 http://forum.epicnet.ru 📜 irc.epicnet.ru 6667 #Code | mIRC scripts, help, discuss, examples
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
https://en.wikichip.org/wiki/mirc/identifiers/$bytes

//echo -a $bytes(1234567,b)

Since $bytes doesn't do it for extremely large $bigfloat numbers, I added an example on that page which can do it using $regex

Joined: Jul 2006
Posts: 4,152
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,152
$bytes cannot do it even for extremely small number,if you want to support decimals, only regex will do a great job. For integer only, then $bytes will do the trick... until you use a very large integer.
With large integer, by default $bytes will stop being 'accurate' at the 2^53 limit. You could enable bigfloat, but that will make it slower AND is that is still limited (a much much larger value than 2^53 but still limited) whereas doing the operation on the string, via regex for example, is extremely fast and should be the prefered method here.

Sat's demonstration: https://forums.mirc.com/ubbthreads.php/ubb/showflat/Number/259070/ ($bytes(1000000000000000.09,db) returns 1,000,000,000,000,000.1)

alias insertcomma var %d $gettok($1,2,46),%r $regsubex($gettok($1,1,46),/(\d)(?=(\d{3})+$)/g,\1 $+ $chr(44)) | if (%d) return $+(%r,.,%d) | return %r

Quote
//echo -ag $insertcomma(653471830)
//echo -ag $insertcomma(653471830.2528507487)

653,471,830
653,471,830.2528507487

Last edited by Wims; 19/08/23 01:47 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 1,541
L
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Dec 2002
Posts: 1,541
Thank you everybody for the quick reply. So I looked into $bytes, but misunderstood the switches. Sometimes I just read things weird. For THIS instance, the MOST amount of characters would be 7 (1,000,000), so $bytes is the perfect fix.

This is why I LOVE the community here. I've used mirc since around 96 and the people here have always been so extremely helpful. You guys rock! Have an awesome day!


Those who fail history are doomed to repeat it

Link Copied to Clipboard