1Z0-809 · Question #205
Locale Currency Symbol Currency Code US $ USD and the code fragment? `` double d = 15; Locale l = new Locale("en", "US"); NumberFormat formatter = NumberFormat.getCurrencyInstance(l)…
The correct answer is A. $15.00. Option A is correct because NumberFormat.getCurrencyInstance(Locale) formats numbers using the locale's native currency symbol (not the ISO code), placing it before the amount with two decimal places - exactly how the US locale renders USD as $15.00. Option B is wrong because…
Question
double d = 15;
Locale l = new Locale("en", "US");
NumberFormat formatter = NumberFormat.getCurrencyInstance(l);
System.out.println(formatter.format(d));
What is the result?Options
- A$15.00
- B15 $
- CUSD 15.00
- DUSD $15
How the community answered
(34 responses)- A85% (29)
- B3% (1)
- C9% (3)
- D3% (1)
Explanation
Option A is correct because NumberFormat.getCurrencyInstance(Locale) formats numbers using the locale's native currency symbol (not the ISO code), placing it before the amount with two decimal places - exactly how the US locale renders USD as $15.00. Option B is wrong because it uses a European placement style (symbol after the number), which no standard English locale produces. Option C is wrong because getCurrencyInstance never outputs the ISO currency code (USD) by default - that would require Currency.getInstance(l).getCurrencyCode(). Option D is wrong because it mixes both the ISO code and symbol together, which is not a format any standard NumberFormat instance produces.
Memory tip: Think of getCurrencyInstance as the "customer-facing" formatter - it shows the friendly symbol ($) the way a price tag would appear in that country, not the banker's ISO code (USD).
Community Discussion
No community discussion yet for this question.