Courseiva

NumberFormat Currency Formatting – Germany Locale Example

Exhibit

Refer to the exhibit.

Exhibit:
```
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.GERMANY);
double value = 1234.5678;
System.out.println(nf.format(value));
```

What is the output of the code in the exhibit?

Quick Answer

The answer is 1.234,57 €. This output is correct because the Java NumberFormat class, when instantiated with the Germany locale via `NumberFormat.getCurrencyInstance(Locale.GERMANY)`, applies locale-specific currency formatting rules: the Euro symbol (€) appears after the amount, a comma serves as the decimal separator, and a dot is used as the thousands grouping separator. On the Oracle Certified Professional Java SE 17 Developer 1Z0-829 exam, this question tests your understanding of how `NumberFormat` handles currency formatting across different locales, a common pitfall being confusion between the US and German formatting conventions. Many candidates mistakenly expect a leading currency symbol or a dot as the decimal separator. A reliable memory tip: for the German locale, think "Euro after, comma for cents, dot for thousands"—just like reading a German price tag.

⚠ Common exam trap

The trap here is that many candidates assume the euro symbol always appears before the amount (like in the US or UK), but the German locale places it after the amount, and the decimal separator is a comma, not a period.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

1.234,57 €

The code uses `NumberFormat.getCurrencyInstance(Locale.GERMANY)`, which formats currency according to the German locale. In Germany, the currency symbol (€) is placed after the amount, a comma is used as the decimal separator, and a period is used as the thousands separator. Thus, 1234.5678 is rounded to two decimal places using half-even rounding and displayed as '1.234,57 €'.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • 1,234.57 €

    Why it's wrong here

    Incorrect: wrong decimal separator for Germany.

  • €1,234.57

    Why it's wrong here

    Incorrect: that is US format with euro symbol.

  • € 1.234,57

    Why it's wrong here

    Incorrect: spacing is wrong for Germany.

  • 1.234,57 €

    Why this is correct

    Correct: German format with comma as decimal.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on 1Z0-829

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Which of the following correctly formats a NumberFormat instance to display a currency value for the US locale with exactly two decimal places, rounding half-up?

easy
  • A.NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); nf.setRoundingMode(RoundingMode.HALF_UP);
  • B.NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); nf.setMinimumFractionDigits(2);
  • C.NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); nf.setMaximumFractionDigits(2);
  • D.NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);

Why A: It uses NumberFormat.getCurrencyInstance(Locale.US) which defaults to exactly two decimal places for the US locale, and explicitly sets the rounding mode to RoundingMode.HALF_UP, satisfying both requirements. Options B and C adjust fraction digits but do not set the rounding mode, so they default to HALF_EVEN. Option D also defaults to HALF_EVEN, not HALF_UP. Therefore, only option A meets the conditions of exactly two decimal places and rounding half-up.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.