Tinderbox Forum

Formatting numbers as currency

This is the first in probably a long list of simple questions (sorry)! I’ve searched the forum and had a look through the various references and I think I know the answer, but I want to check.

I have an “Opportunity” prototype for modelling a services sale (implementing our own software). In there I have an Amount attribute which is a number but I want to see it formatted as currency in the Attribute Browser. Is there a way to apply formatting to an attribute, or do I just create a new string attribute and use a rule to write a formatted copy of the source Amount into it (and then only display the new string attribute)?


/edit - Adding the attribute to the prototype and then “resetting” all my notes with a stamp to set the KeyAttributes and Rule to null did the trick. It’s just a shame the Attribute Browser can’t show a formatted total in the group row.

/edit2 - Tinderbox is way too much fun to be work. :slight_smile:

Understand that you’ve probably worked this out, and also agree that the learning-through-tinkering is part of the satisfaction / mystery / self-education. A few extra points:

  • You probably know this already, but the way to format string data as currency is with the .format("$") operator. It’s described in (of course) aTbRef here. It uses whatever is your computer’s locally set currency.

  • Thus if you’re starting with number data, and want to get a currency display, you first transfer the numeric info to a string attribute, and then you format that string attribute. For instance, if the underlying numeric info were stored in an attribute called $NumericInfo, you could create a new string attribute called $CurrencyDisplay and apply a rule like: $CurrencyDisplay=NumericInfo.format("")

  • You can format number -type data and attributes to various degrees of precision, as explained [here]

  • The screenshot below illustrates how I’ve used formatting and summaries in the attribute browser. This falls short of elegance in one minor way but does the job. Here’s the image, followed by an explanation:

This is for a financial-data file. In the attribute browser, I want to see items grouped by category – with a summary by category. This one shows a currency-formatted entry for each item, and then a total, listed as “Sum,” for the category as a whole.

The minor inelegance, which I’m sure one of our gurus can straighten out: To the best of my knowledge, the currency format – .format("$") – works only on string data, so I have a separate column called $FormattedSum which is the numeric entries converted to a string and then nicely formatted. But to have a category-total figure – the “Sum” in the upper right-hand corner – I need to work from actual number data, thus the inclusion of the $Sum column, which is a number-type attribute. I believe that I can’t have the summary figure without showing the column itself.

In any case this is a half-of-one-percent inelegance, for a display that shows me just what I want. I use this for all kinds of accounting purposes, and I get: individual entries, respective dates, individual amounts nicely formatted, and then the sum for the category as a whole. Offered for your further tinkering.


Thanks for the reply. This is pretty much exactly where I ended up, which is a nice confirmation that I’m heading in the right direction. The only difference is that I create the string as follows:

$Amount$="$ "+$Amount.format(“L”);

The reason being that if I format with the “$” format string it turns the amount into “£” because I’m in the UK - we do business in USD so I need it to be an actual $. (The “L” format adds thousands separators).

Thanks again!