I'm looking for a function to seperate numbers with commas, to make it human readable.
ie:
999,999,999
Does anyone have this to hand?
Many thanks.
ie:
999,999,999
Does anyone have this to hand?
Many thanks.
SuperStrict Function CommaNumber$(v:Int,div$=",") Local s$=v If s$="" Return "" Local n$ For Local t:Int=Len(s$)-1 To 0 Step -1 n=Mid(s,1+t,1)+n If t And Not ((Len(s)-t) Mod 3) n=div+n Next Return n End Function Function CommaString$(s$,div$=",") If s$="" Return "" Local n$ For Local t:Int=Len(s$)-1 To 0 Step -1 n=Mid(s,1+t,1)+n If t And Not ((Len(s)-t) Mod 3) n=div+n Next Return n End Function Print CommaString("1") Print CommaString("12") Print CommaString("123") Print CommaString("1234") Print CommaString("12345") Print CommaString("123456") Print CommaString("1234567"," ") Print CommaString("12345678",".") Print CommaNumber(10001001,".") End
Function FormatNumber:String(num:String) Local i:Int=num.Length-1,j:Int=0,out:String Repeat out=Chr(num[i])+out i:-1 j:+1 If j=3 And i>=0 Then out=","+out j=0 EndIf Until i<0 Return out EndFunction Local num:Int=1 For Local i:Int=1 Until 11 Print FormatNumber(num) num:*10 Next