Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Number.toLocaleString vs Intl.NumberFormat
(version: 0)
Comparing performance of:
Intl.NumberFormat vs Number.toLocaleString
Created:
5 years ago
by:
Registered User
Jump to the latest result
Tests:
Intl.NumberFormat
const currencyPlayNumber = 1; const translatedString = new Intl.NumberFormat(undefined, { style: 'currency', currency: 'RUB', }).format(currencyPlayNumber);
Number.toLocaleString
const currencyPlayNumber = 1; const translatedString = currencyPlayNumber.toLocaleString(undefined, { style: 'currency', currency: 'RUB', })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Intl.NumberFormat
Number.toLocaleString
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Intl.NumberFormat
35867.6 Ops/sec
Number.toLocaleString
38260.2 Ops/sec
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark compares two methods for formatting numbers as currency in JavaScript: `Intl.NumberFormat` and `Number.toLocaleString`. **Options Compared:** * **`Intl.NumberFormat`**: This method offers fine-grained control over number formatting, including currency symbols, locale-specific conventions, and styles (e.g., "currency", "decimal"). It's more powerful but potentially slower due to its complexity. * **`Number.toLocaleString`**: A simpler method that automatically formats numbers according to the user's browser locale settings. It's generally faster but provides less control over specific formatting details. **Pros and Cons:** | Method | Pros | Cons | |--------------|-----------------------------------------|------------------------------------------| | `Intl.NumberFormat` | Highly customizable, supports various locales and styles | More complex, potentially slower | | `Number.toLocaleString` | Simpler to use, generally faster | Less control over formatting details | **Libraries:** None used in this benchmark. **Special JS Features/Syntax:** This benchmark uses standard JavaScript features like objects, methods, and strings without any specific syntax beyond the standard language constructs. **Alternatives:** While `Intl.NumberFormat` and `Number.toLocaleString` are the primary options for currency formatting, other libraries might provide additional features or optimizations: * **React Intl:** A library that integrates with React applications and offers robust internationalization capabilities, including currency formatting. * **Moment.js:** A widely-used date and time library that also includes currency formatting functions. In essence, the choice between these methods depends on the level of customization required and performance needs. If precise control over the currency format is paramount, `Intl.NumberFormat` is preferred; otherwise, `Number.toLocaleString` offers a good balance of simplicity and speed.
Related benchmarks:
Intl.NumberFormat vs toLocalString
Intl.NumberFormat vs toLocalString 2
Intl.NumberFormat vs toLocalString ( predefine the NumberFormat instance )
cached Intl.NumberFormat vs toLocalString
Intl.NumberFormat vs toLocalString yoyo
Comments
Confirm delete:
Do you really want to delete benchmark?