Course contentsShow
← JavaScript
Lesson 2224 of 2,72346. InternationalizationFree lesson

Numeric vs Always Options

Controlling whether output is numeric ('in 1 day') or textual ('tomorrow') with the numeric option.

Numeric vs Always Options

What you'll learn: How to control whether Intl.RelativeTimeFormat outputs numeric values like "in 1 day" or textual equivalents like "tomorrow".

The Core Choice

When formatting relative times, you can decide between numeric output (always showing numbers) and textual output (using words like "yesterday," "tomorrow," "last month" when available). The numeric option controls this behavior.

Understanding the Two Modes

Think of it like choosing between a digital clock display versus saying "noon" or "midnight." Sometimes precise numbers are clearer; other times natural language reads better.

The numeric option accepts two values:

  • "always" (default): Forces numeric output even when textual alternatives exist

    • Result: "in 1 day" or "1 day ago"
  • "auto": Uses textual alternatives when available, falls back to numeric otherwise

    • Result: "tomorrow" or "yesterday" when possible

Practical Examples

const numericFormatter = new Intl.RelativeTimeFormat('en', { 
  numeric: 'always' 
});

numericFormatter.format(1, 'day');    // "in 1 day"
numericFormatter.format(-1, 'day');   // "1 day ago"

const autoFormatter = new Intl.RelativeTimeFormat('en', { 
  numeric: 'auto' 
});

autoFormatter.format(1, 'day');       // "tomorrow"
autoFormatter.format(-1, 'day');      // "yesterday"
autoFormatter.format(2, 'day');       // "in 2 days" (no text equivalent)

With "auto", the formatter intelligently chooses the most natural phrasing. For values without special words (like "in 3 days"), it automatically falls back to numeric formatting.

Key Takeaway: Use numeric: 'auto' for human-friendly relative times that feel natural in conversation, or stick with numeric: 'always' when consistent numeric formatting is important for your interface.