Dominik
Dominik

Reputation: 396

Formatting Numbers without locale

The user can specify a file output format at the GUI. Especially he can define a number format. The first idea was to let him specify a format which can be used with DecimalFormat, but DecimalFormat has at least two main disadvantages for my usecase:

StringFormat cannot do this either. So my question is if you know any library which already handles this problem, or do i have to program a simple formatter myself.

Upvotes: 3

Views: 1739

Answers (2)

Vinil Chandran
Vinil Chandran

Reputation: 1561

DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
DecimalFormat decimalFormat = new DecimalFormat("##.##");
decimalFormat.setDecimalFormatSymbols(otherSymbols);

Upvotes: 2

user207421
user207421

Reputation: 310874

It uses the locale of the user

Not so. From the Javadoc:

"To obtain a NumberFormat for a specific locale, including the default locale, call one of NumberFormat's factory methods, such as getInstance(). In general, do not call the DecimalFormat constructors directly".

Upvotes: -1

Related Questions