Hello
I would like to format numbers (doubles) for display. I want to use the
methods NumberFormat.setMinimumFractionDigits() for rounding, but I am
annoyed by the Locale.
How can I get rid of the Locale formatting and get back a simple number
format (with a dot as decimal separator).
Expected: 1234567.89
US: 1,234,567.89
My Own Locale: 1'234'567.89
How to get rid of all these ' and , ?
Thanks Phil
Robert Klemme - 12 Mar 2007 12:24 GMT
> Hello
> I would like to format numbers (doubles) for display. I want to use the
[quoted text clipped - 10 lines]
>
> Thanks Phil
Please read the API docs. IIRC you can set a Locale on creation (or
later). You can also explicitly set the formatting symbols.
Kind regards
robert
Philipp - 12 Mar 2007 12:30 GMT
> Hello
> I would like to format numbers (doubles) for display. I want to use the
[quoted text clipped - 8 lines]
>
> How to get rid of all these ' and , ?
Ok I got my solution. Sorry for the noise.
myFormat = new DecimalFormat("##0.#####E0");
does what I want (which is not the example I wrote above, but I know that).
But I can't understand why in the JavaDoc (at
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html)
they say not to instanciate this class directly but to use the factory
method from NumberFormat.
I can't apply a pattern if I don't know if it is a DecimalFormat. In the
doc they say to do this:
NumberFormat f = NumberFormat.getInstance(loc);
if (f instanceof DecimalFormat) {
((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true);
}
but what do you do if "f" is not an instanceOf DecimalFormat? Are you
suppose to die of a sudden death?
Phil