Format a variable with thousands separators

I’ve read the documentation up and down; is there a way to set a variable to automatically insert the thousands comma separators? “Format” seems to require a set number to work.

I know in VB6, I used (for example): Cash: $" & FormatNumber(cash, 0) which would insert the commas into the right places. The number can vary greatly, it should be noted.

https://documentation.xojo.com/index.php/Format

Dim s as String s=Format(3560.3, "\\$###,##0.00")

HINT: use currency, not double for handling money!!

As I stated above, I’ve read about Format and it seems to only take set numbers in the examples i’ve seen, not variables. The ‘cash’ variables is in this case a whole Integer number, not money in my case.

I already tried to display it as Format(cash, “##,####”) and I get a syntax error.

Please post the entire snippet of code that contains your “syntax error”

as the use of Format as Oliver specified as well as the partial example you provided ARE correct

dim cash as integer
cash=1234
msgbox format(cash,"##,####")

Hmm, yep got it to work. I ended up having to dim a string, then put the formatted ‘cash’ variable into it. Then it displays fine.
I assume this code is the best way to do it? :slight_smile:

Dim cashst as String cashst=Format(cash, "##,###") Label1.Text = "Cash: $" + cashst

there is no “best” way to do anything… there are BAD ways… but a comparative analysis requires TWO methods… so it is impossible to say if this “way” if “better” (or worse) than another way, without know what the “other” way is

These work too:

cashst = Format(cash, "#,")
cashst = Format(cash, "#,0")
cashst = Format(cash, "#,0.00")

[quote=84227:@Derek DiBenedetto]Hmm, yep got it to work. I ended up having to dim a string, then put the formatted ‘cash’ variable into it. Then it displays fine.
I assume this code is the best way to do it? :slight_smile:

Dim cashst as String cashst=Format(cash, "##,###") Label1.Text = "Cash: $" + cashst[/quote]
The result of the Format function is a string, I’m assuming that you were trying to assign the formatted text to your integer ‘Cash’ variable, which would give you a syntax error.