Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
formatting number with commas
#2
member function str.Format100
Code:
Copy      Help
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.
pi


Messages In This Thread

Forum Jump:


Users browsing this thread: 5 Guest(s)