javascript / latest / global_objects / intl / numberformat / formatrange.html /

Intl.NumberFormat.prototype.formatRange()

The Intl.NumberFormat.prototype.formatRange() method formats a range of numbers according to the locale and formatting options of the Intl.NumberFormat object from which the method is called.

Syntax

formatRange(startRange, endRange)

Parameters

startRange

A Number or BigInt.

endRange

A Number or BigInt.

Description

The formatRange getter function formats a range of numbers into a string according to the locale and formatting options of this Intl.NumberFormat object from which it is called.

Examples

Using formatRange

Use the formatRange getter function for formatting a range of currency values:

const nf = new Intl.NumberFormat("en-US", {
  style: "currency",
  currency: "USD",
  maximumFractionDigits: 0,
});

console.log(nf.formatRange(3, 5)); // → "€3 – €5"
console.log(nf.formatRange(2.9, 3.1)); // → "~€3"
const nf = new Intl.NumberFormat("es-ES", {
  style: "currency",
  currency: "EUR",
  maximumFractionDigits: 0,
});

console.log(nf.formatRange(3, 5); // → "3-5 €"
console.log(nf.formatRange(2.9, 3.1); // → "~3 €"

Specifications

Browser compatibility

Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet Deno Node.js
formatRange
No
No
No
No
No
15.4
No
No
No
No
15.4
No
No
No

See also

© 2005–2022 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange