Intl.NumberFormat.prototype.formatRange
Formats a range of numbers according to the locale and formatting options of this Intl.NumberFormat object
Syntax
numberFormat.formatRange(startRange, endRange)Parameters
| Parameter | Type | Description |
|---|---|---|
| startRange | number | bigint | The start of the range |
| endRange | number | bigint | The end of the range |
Return Value
A string containing the formatted range
Examples
const fmt = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' })
console.log(fmt.formatRange(10, 50)) // '$10.00 – $50.00'const fmt = new Intl.NumberFormat('en-US')
console.log(fmt.formatRange(1000, 5000)) // '1,000–5,000'const fmt = new Intl.NumberFormat('en', {
style: 'unit',
unit: 'kilogram'
})
console.log(fmt.formatRange(5, 10)) // '5–10 kg'Understanding Intl.NumberFormat.prototype.formatRange
The Intl.NumberFormat.prototype.formatRange method in JavaScript formats a range of numbers according to the locale and formatting options of this Intl.NumberFormat object. It belongs to the Intl.NumberFormat object and is one of the most widely used methods for working with intl.numberformat values in modern JavaScript and TypeScript applications.
The method signature is numberFormat.formatRange(startRange, endRange). It accepts 2 parameters: startRange, endRange. When called, it returns a string containing the formatted range. Understanding when and how to use formatRange() helps you write more expressive, readable code.
Common use cases for Intl.NumberFormat.prototype.formatRange include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like intl-numberformat-format, intl-numberformat, intl-datetimeformat-formatrange, enabling you to chain operations together for complex data manipulation pipelines.
Supported in Chrome 106+, Firefox 116+, Safari 15.4+, Edge 106+.
Browser Compatibility
Supported in Chrome 106+, Firefox 116+, Safari 15.4+, Edge 106+.
Related Methods
Intl.NumberFormat.prototype.formatFormats a number according to the locale and formatting options of this Intl.NumberFormat object
Intl.NumberFormatCreates an Intl.NumberFormat object that enables language-sensitive number formatting
Intl.DateTimeFormat.prototype.formatRangeFormats a date range in the most concise way based on the locale and options set on the DateTimeFormat object
More Intl.NumberFormat Methods
Other methods in the Intl.NumberFormat object
Related Tools
More Intl.NumberFormat Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.