Posts: 1,769
Threads: 410
Joined: Feb 2003
is the an easy way to put a character into a number to mark the thousands, millions etc?
285798181
to this
285,798,181
or this if not in the US
285.798.181 :wink:
Posts: 1,271
Threads: 399
Joined: Mar 2003
member function str.Format100
function [VARIANT'numberstring] [$delimiter];;1245657864 "."
;Formats numberstring 1245657864 to 1.245.657.864
;Default: itself.
;delimiter default is '.'
;!!! NOT implemented: check for double !!!
;EXAMPLES
;str s
;s.Format100("1245657864")
;s=1245657864
;s.Format100
;s.Format100(252545 ",")
;out s
if(!numberstring) numberstring=this;else this=numberstring
if(!delimiter) delimiter="."
ARRAY(int) h.create(3)
h[0] = 9
h[1] = 6
h[2] = 3
if this.len>=10
,this.insert(delimiter this.len-h[0])
,this.insert(delimiter this.len-h[1])
,this.insert(delimiter this.len-h[2])
else if this.len>=7
,this.insert(delimiter this.len-h[1])
,this.insert(delimiter this.len-h[2])
else if this.len>=4
,this.insert(delimiter this.len-h[2])
double needs to be implemented.
Posts: 1,769
Threads: 410
Joined: Feb 2003
HA!
it's a beautiful thing; thanks!
I'll watch out for the double.
Posts: 12,072
Threads: 140
Joined: Dec 2002
This also works for double.
str s="-1234567.1234567"
strrev s
s.replacerx("(\d{3})(?=\d+($|[^\.\w]))" "$1,")
strrev s
out s
There should be an API function for this, but I could not find.
Posts: 1,769
Threads: 410
Joined: Feb 2003
"strrev" is that new?
it doesn't show up coloured for me.
Posts: 12,072
Threads: 140
Joined: Dec 2002
For QM versions before 2.2.0, declare it:
dll msvcrt [_strrev]$strrev $string
Posts: 1,769
Threads: 410
Joined: Feb 2003
Posts: 12,072
Threads: 140
Joined: Dec 2002
It will become coloured after you run the code and reopen the macro or refresh colors.
In QM 2.2.0, everything that is in WINAPI don't have to be declared in macros.
Posts: 1,769
Threads: 410
Joined: Feb 2003
yep...there it is.
man, RX kicks my can every time!
do you know of a good book on RX?
PS: thanks! i'll have to rember the strrev thing; could come in handy somewhere else too.
Posts: 1,769
Threads: 410
Joined: Feb 2003
Member function: str.AddCommasToNumbers
function$
;Adds commas to large numbers.
;Note: the number must become a string before sending to this funcion.
;str s="1234567.1234567"
;s.AddCommasToNumbers
;out s
strrev this
this.replacerx("(\d{3})(?=\d+($|[^\.\w]))" "$1,")
strrev this