Formatting Currency

Is there way to format a currency other than as designated by the local system.

For me $Price(z).format("$") works for USD but I can’t get it to work for £ $Price(z).format("£").

Is there a way around this?

I can get what I want to do in another way but…

a small function to format the string the way you like…?!

Yes, this is what I meant by “I can get what I want to do in another way but…”, I was just seeing if I was missing something with the formatting style.

Your quotes aren’t the same type.

On my UK system, Number.format("$") gives me a string with the the number rounded to 2 decimal places, formatted with thousands separator as per my locale and with a ‘£’ prefix.

Thus 4525.3456 becomes £4,525.35.

I guess you need to swap locale(), but I’m not that sure if currency formatting is really intended to work for any currency.

Copy and paste error, produces the same effect.

Yes, I’m looking to specify local for a note, but from the documentation, it is not clear to me how to do this. How would you use local() in the action code? it does not appear to be a .operator.

You call locale() (note the ‘e’) as described, supplying the relevant locale string. I do note that the article states:

Note that changing the locale() can be fairly time-consuming, as lots of machinery must be torn down and rebuilt for each change.

I take that to not 'just ’ change locale back and forth for casual reasons. I suspect your usage falls into the latter.

I better answer really needs more info as to the context. The following approach seems easier. I’m in UK locale so I’ll set a ‘price’ in USD:

var:number vNum = $MyNumber.format("2");
$Text = "$"+ vNum.format("l"); // '$4,525.35'

I tried chaining .format() calls but it didn’t work So, we first make a two-DP number variable, then use locale-dependent styling. We could as easily add USD instead:

var:number vNum = $MyNumber.format("2");
$Text = vNum.format("l")+" USD"; // 4,525.35 USD

But if you want Euros in German delimiters, i.e. €4.525,35 not English-style €4,525.35 then you would need to change active locale as .format("l") is locale dependent for things like thousands separators and decimal separator. Also bear in mind, locale is accessing the users localisation settings for the given locale so if the user has for any reason further customised their per-locale setting, results may vary. But, that’s the whole point on different locale. Diversity FTW!

Bottom line, I don’t think there is an answer as simple as you were hoping for.

1 Like

Ok…thanks. I am already using the strategy noted above. Was hoping for a simple answer, that the above is not simple enough.

1 Like