Gatsbimantico
Gatsbimantico

Reputation: 1830

Using Intl.NumberFormat, is it possible to have three minIntegerDigits that are non-zero?

When using scientific notation, writing 1000g is the same as 1kg.

When using Intl.NumberFormat with the compact notation and currency style, it switches automatically from £999 to £1k.

When using also the property minIntegerDigits=3, I expected it to wait until having three integer digits to switch, so it would be from £99,999 to £100k. Instead it adds leading zeros, switching from £999 to £001k.

Is it possible to achieve the following formats:

£99,999.99 then £100.00k

£9,999.99k then £10.00M

£9,999.99M then £10.00B

? Or at least something similar.

My thought was to divide the number to get it in the integer size I need, then combine the output of formatToParts taking the "literal" from one and the "integer" and "fraction" parts from another. But it just feels too messy. (pseudo-code, something like)

numericalParts = formatToParts(value/1000)
semanticalParts = formatToParts(1000)

return numericalParts.integer + numericalParts.fraction + semanticalParts.literal + semanticalParts.currency


Upvotes: 0

Views: 1169

Answers (0)

Related Questions