udfStrNumThousands (numstr, mode)
;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfstrnumthousands",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfstrnumthousands

#DefineFunction udfStrNumThousands (numstr, mode)
; #DefineFunction udfStrNumCommaize (numstr, mode)

If (numstr=="") Then Return (numstr)

If mode
   point = "," ; European style
   sep = "."
Else
   point = "." ; American style
   sep = ","
EndIf

numstr = StrClean(numstr,StrCat(point,"0123456789"),"",@TRUE,2) ; Allow digits and decimal point.
numle = ItemExtract(1,numstr,point)
numri = ItemExtract(2,numstr,point)
numle = StrSub(numle,StrScan(numle,"123456789",1,@FWDSCAN),-1) ; Delete leading zeroes.
numri = StrSub(numri,1,StrScan(numri,"123456789",StrLen(numri),@BACKSCAN)) ; Delete trailing zeroes.

If (numle == "")
   outle = "0"
Else
   outle = ""
   len = StrLen(numle)
   While (len > 3)
      outle = ItemInsert(StrSub(numle,len-2,3),0,outle,sep)
      numle = StrSub(numle,1,len-3)
      len = StrLen(numle)
   EndWhile
   outle = ItemInsert(numle,0,outle,sep)
EndIf
numout = outle

If (numri == "")
   ; numri = "0"
Else
   outri = ""
   len = StrLen(numri)
   While (len > 3)
      outri = ItemInsert(StrSub(numri,1,3),-1,outri,sep)
      numri = StrSub(numri,4,-1)
      len = StrLen(numri)
   EndWhile
   numri = StrFix(numri,"0",3)
   outri = ItemInsert(numri,-1,outri,sep)
   numout = StrCat(outle,point,outri)
EndIf

Return (numout)
;..........................................................................................................................................
; This function returns a number string formatted in 3-digit packets ("Commaize").
; mode = 0 = American number style = "1,234.567,890"
; mode = 1 = European number style = "1.234,567.890"
;..........................................................................................................................................
; Detlev Dalitz.20020614
;..........................................................................................................................................
#EndFunction

:skip_udfstrnumthousands
;------------------------------------------------------------------------------------------------------------------------------------------


; --- test ---

number1 = "00001234567890000"
str1 = udfStrNumThousands (number1,0)
; ==> "1,234,567,890,000"

number2 = "00001234.567890000"
str2 = udfStrNumThousands (number2,0)
; ==> "1,234.567,890"

number3 = "0000123.4567890000"
str3 = udfStrNumThousands (number3,0)
; ==> "123.456,789"

msgtitle = "Demo  udfStrNumThousands(numstr,mode)"
msgtext  = ""
msgtext  = StrCat(msgtext,number1,@TAB," = ",str1,@CRLF)
msgtext  = StrCat(msgtext,number2,@TAB," = ",str2,@CRLF)
msgtext  = StrCat(msgtext,number3,@TAB," = ",str3,@CRLF)
Message(msgtitle,msgtext)

Exit
;------------------------------------------------------------------------------------------------------------------------------------------
;*EOF*