Vue Academy · Lesson

Number, Date, and Currency Formatting

n() for numbers, d() for dates, datetime formats, numberFormats per locale.

Lesson 4 of 413 steps

Number, Date, and Currency Formatting is a free Vue Academy lesson on CoddyKit. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, and your progress syncs across the web and the CoddyKit app. The Vue Academy course includes 4 lessons in total.

Numbers and Dates Vary by Locale

1,000.50 in the US is 1.000,50 in much of Europe. Dates and currencies differ too. Vue I18n wraps the browser Intl APIs so numbers, dates, and money render correctly per locale.

Configuring numberFormats

Define named number formats per locale in the numberFormats option of createI18n. Each named format is an Intl.NumberFormat options object.

const i18n = createI18n({
  locale: "en",
  numberFormats: {
    en: {
      currency: { style: "currency", currency: "USD" },
      decimal: { style: "decimal", minimumFractionDigits: 2 },
    },
  },
})

The n() Function

Format a number with n(value, formatName) from useI18n(), or $n in templates. It uses the named format for the active locale.

const { n } = useI18n()

n(1234.5, "decimal") // "1,234.50" in en

Currency Formatting

The currency style adds the right symbol and grouping. The currency code in the format config controls which symbol appears.

const { n } = useI18n()

n(49.99, "currency") // "$49.99" in en

Locale-Aware Currency Output

Add the same named format under each locale with locale-appropriate settings. Switching locale changes grouping, decimal marks, and symbol placement automatically.

numberFormats: {
  en: { currency: { style: "currency", currency: "USD" } },
  tr: { currency: { style: "currency", currency: "TRY" } },
}
// n(49.99, "currency") => "$49.99" (en) or "TRY 49,99" style (tr)

Percentages

The percent style multiplies by 100 and appends a percent sign per locale.

numberFormats: {
  en: { percent: { style: "percent", maximumFractionDigits: 1 } },
}

n(0.256, "percent") // "25.6%"

Configuring datetimeFormats

Date formatting mirrors numbers. Define named formats under datetimeFormats, each an Intl.DateTimeFormat options object.

const i18n = createI18n({
  locale: "en",
  datetimeFormats: {
    en: {
      short: { year: "numeric", month: "short", day: "numeric" },
      long: { dateStyle: "full", timeStyle: "short" },
    },
  },
})

The d() Function

Format a Date with d(value, formatName) (or $d in templates). Pass a Date object or a timestamp.

const { d } = useI18n()

d(new Date("2026-05-29"), "short") // "May 29, 2026" in en

Locale-Aware Dates

As with numbers, provide the named date format per locale. The same call yields a localized order and month names when the locale changes.

datetimeFormats: {
  en: { short: { year: "numeric", month: "short", day: "numeric" } },
  tr: { short: { year: "numeric", month: "short", day: "numeric" } },
}
// d(date, "short") => "May 29, 2026" (en) / "29 May 2026" (tr)

Using Format Helpers in Templates

In templates, use $n and $d with a value and the named format.

<template>
  <p>Total: {{ $n(total, "currency") }}</p>
  <p>Updated: {{ $d(updatedAt, "short") }}</p>
</template>

One-Off Inline Options

Beyond named formats you can pass an inline options object as the second argument for a one-off format without defining it in config.

const { n, d } = useI18n()

n(0.5, { style: "percent" })           // "50%"
d(new Date(), { weekday: "long" })     // "Friday"

Quick Check

Check your understanding of locale-aware formatting.

Recap

You learned locale-aware formatting:

  • Configure named formats under numberFormats and datetimeFormats per locale.
  • n(value, name) / $n formats numbers — decimal, currency, percent styles.
  • d(value, name) / $d formats dates.
  • Switching locale changes grouping, decimal marks, symbols, and date order automatically.
  • You can also pass an inline options object for one-off formatting.
Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
42
Lessons
156

Frequently Asked Questions

Is the “Number, Date, and Currency Formatting” lesson free?

Yes — any 3 lessons of the Vue Academy learning path, including “Number, Date, and Currency Formatting”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Vue Academy course includes 4 lessons in total.

What will I learn in “Number, Date, and Currency Formatting”?

n() for numbers, d() for dates, datetime formats, numberFormats per locale. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Vue Academy?

No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.

How long does the “Number, Date, and Currency Formatting” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Vue Academy lesson?

Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. vue-i18n Setup and Message Files
  2. useI18n Composable and t() Function
  3. Pluralization and Linked Messages
  4. Number, Date, and Currency Formatting
← Back to Vue Academy