WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Number Conversion

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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
File Created: 2000:09:28:12:56:16
Last Updated: 2000:09:28:12:56:16