Name: gsC80088 Date: 02/16/99
1. set a new currency symbol "F" in a DecimalFormatSymbol object
2. call setDecimalFormatSymbols on a DecimalFormat
3. call format on the updated DecimalFormat
4. I expected to see the formated string "F1234.56", but instead
the symbol doesn't appear to be updated. Instead, the output is
"$1234.56", which seems to have ignored the new currency symbol.
Here's the code:
package javai18n.currency;
import java.text.*;
public class MixCurrency {
public static void main(String[] args) {
NumberFormat nfUS = NumberFormat.getCurrencyInstance(java.util.Locale.US);
DecimalFormatSymbols symbolsFR = new DecimalFormatSymbols(java.util.Locale.FRANCE);
String frenchCurrency = symbolsFR.getCurrencySymbol();
DecimalFormatSymbols symbolsUS = ((DecimalFormat)nfUS).getDecimalFormatSymbols();
symbolsUS.setCurrencySymbol(frenchCurrency);
((DecimalFormat)nfUS).setDecimalFormatSymbols(symbolsUS);
double amount = 1234.56;
System.out.println(nfUS.format(amount));
// Although I expect the following:
// F1,234.56
// It simply prints the typical US pattern:
// $1,234.56
//
// How can I change the currency for a format without changing
// other parts of the pattern?
}
}
(Review ID: 53519)
======================================================================
- relates to
-
JDK-4294646 Change in DecimalFormat serialized form
-
- Resolved
-