+ Start a Discussion
WizradWizrad 

Double .format(), locales, non-removable whitespace

Hi all,

 

I've got a currency field on a record where the currency iso code is CAD.

 

If I take the value from the currency field, put it in a local variable of type double, then format the double, you end up with the number formatted to the CAD locale.

 

For example, "14 000,24" or 14 thousand and 24 cents.

 

Client has asked that I transform this back to the US based format, "14,000.24".

 

You may be wondering, why even use .format()?  I use .format() because it gives me commas (or when currencyisocode = 'CAD' whitespace) every three digits.

 

Anyways...I am able to change "14 000,24" to "14 000.24" easily.  The problem is changing the whitespace to a comma.  You could try to trim this string, you could try to replace all whitespace with commas in this string, and it doesn't matter.  It ignores your requests, returning the original string.  What mysterious character is FORCE using here?  Would I be better off not using .format(), and instead using Pattern and Matcher classes to add the commas in correctly?

 

Thanks!

vanessenvanessen

but if you try forcing the comma yourself with double. it won't be displayed as you want cause it is a double after all.you could do it with string.Wish i'm not wrong on this.