The toLocaleString()
function in the Underscore library provides a way to convert a number to a locale-specific string. The function takes two parameters: the number to be converted, and an optional locale identifier.
Here's an example that demonstrates how to use toLocaleString()
function:
index.tsx450 chars12 lines
In this example, we load the Underscore library with require()
, and then use the toLocaleString()
function to convert the number
variable to a locale-specific string. We pass 'fr-CA'
as the locale identifier to format the number for Canadian French, and 'en-US'
to format the number for US English.
The output produced by toLocaleString()
will differ slightly based on the locale specified. For instance, the "fr-CA"
example separates the integral and fractional part of the number with a coma and a non-breaking space, while the "en-US"
example separates them with a period.
gistlibby LogSnag