How to Format a Number with Commas for a Nice Display
Keywords: format number commas
Question:
I have a variable with a large value, 250000000, and I would like to display it in a message as 250,000,000. I
don't see any formats available in the Winbatch functions. Is this possible?
Answer:
; -----------
; Format a number with commas for a nice display
; -----------
tot=250000000
If StrLen(tot) < 9 Then tot = StrCat(StrFill("", 9 - StrLen(tot)), tot)
tot = StrCat(StrSub(tot,1,3),",",StrSub(tot,4,3),",",StrSub(tot,7,3))
tot = StrTrim(tot)
If StrSub(tot, 1, 1) == "," Then tot = StrSub(tot, 2, StrLen(tot) - 1)
tot = StrTrim(tot)
If StrSub(tot, 1, 1) == "," Then tot = StrSub(tot, 2, StrLen(tot) - 1)
tot = StrTrim(tot)
Message("Formatted number", tot)
Article ID: W14657
Filename: Format Numbers with Commas for a Nice Display.txt