Courseiva
User Interface →mediumMultiple Choice

SF-PD2 User Interface Practice Question

A developer is building a Lightning Web Component that must render a large list of order records retrieved from Apex. The component displays each order's formatted total, which follows the user's locale (for example, 1.234,56 € in Germany versus $1,234.56 in the US). Which approach correctly formats each order total for the current user?

⚠ Common exam trap

The trap here is assuming the browser's locale matches the Salesforce user's locale setting, which is not guaranteed in Lightning Experience.

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

✓

Import the formatNumber function from lightning/i18n and call it with the numeric value and the appropriate format string.

Formatting numbers for the running user requires respecting the Salesforce locale, not the browser locale. The lightning/i18n module's formatNumber function is the supported way to format numeric values client-side so results match the user's Salesforce locale. Relying on browser-based formatting or Apex-side string concatenation produces inconsistent output across users and locales.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Use the toLocaleString() method on the JavaScript Number object inside the component's renderedCallback.

    Why it's wrong here

    toLocaleString() relies on the browser's locale, which in Lightning Experience is not guaranteed to match the Salesforce user's locale setting. In a German org accessed from an en-US browser, totals would render in US format, producing incorrect currency presentation. It also does not respect Salesforce locale, currency, or the org's default currency, so results diverge from server-side formatting.

  • ✗

    Call the Apex method with a @AuraEnabled(cacheable=true) annotation and rely on Apex to return the formatted string.

    Why it's wrong here

    Apex runs in the system context and does not automatically localize numbers to the running user's locale. Returning a pre-formatted string from Apex hard-codes the format and breaks when the user changes locale. The cacheable annotation only affects client-side caching and does not influence formatting, so this approach produces incorrect display values.

  • ✗

    Bind the raw numeric field from Apex directly into the template and let the browser's Intl.NumberFormat format it automatically.

    Why it's wrong here

    Lightning Web Component templates do not automatically run Intl.NumberFormat on interpolated values. Binding a raw number renders the unformatted JavaScript number, so no thousands separators or currency symbols appear. Formatting must be done explicitly in JavaScript before assigning the value to a property used in the template.

  • ✓

    Import the formatNumber function from lightning/i18n and call it with the numeric value and the appropriate format string.

    Why this is correct

    lightning/i18n exposes formatNumber, which formats values according to the running user's Salesforce locale. This keeps the displayed total aligned with the user's language and region settings and matches how Salesforce formats numbers elsewhere. Using it avoids browser-locale drift and keeps formatting consistent across the org's users regardless of their OS or browser settings.

About these practice questions

One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Salesforce exam blueprint

This SF-PD2 practice question is part of Courseiva's free Salesforce 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 SF-PD2 exam.