[TF] mylib patch: num2commas()
Brought to you by:
kenkeys
|
From: tinyfugue at attbi.c. (Galvin) - 2003-04-16 06:00:10
|
This function has been updated to support floating point numbers. Still
supports whole numbers as well.
;==============================================================================
; num2commas()
;
; returns a number formatted with comma's
; USAGE:
; x := num2commas(value)
;
; x : Value returned with commas. Example 1,345 from 1345.
; value : Any number.
;
; NOTES: x can also be floating point.
;==============================================================================
/def num2commas = \
/let st_ %{1} %;\
/let pos_ 0 %;\
/let count_ 0 %;\
/let count2_ 0 %;\
/let st2_ 0 %;\
/let frac_ 0 %;\
/test st2_ := '' %;\
/test pos_ := strstr(st_, '.') %;\
/IF (pos_ > -1) \
/test count_ := pos_ %;\
/test frac_ := substr(st_, pos_) %;\
/ELSE \
/test count_ := strlen(st_) %;\
/test frac_ := '' %;\
/ENDIF %;\
/WHILE (--count_ >= 0) \
/IF ( (count2_ = 3) & (substr(st_, count_, 1) !~ '-') ) \
/test st2_ := strcat(',', st2_) %;\
/test count2_ := 0 %;\
/ENDIF %;\
/test st2_ := strcat(substr(st_, count_, 1), st2_) %;\
/test ++count2_ %;\
/DONE %;\
/return strcat(st2_, frac_)
|