I'm having a hard time finding a way to use (Compact Number Format) with NumberFormatter
As a reference here's a working example with JavaScript
new Intl.NumberFormat('en-GB', {
notation: "compact"
}).format(987654321);
// → 988M
new Intl.NumberFormat('en-GB', {
notation: "compact"
}).format(78656666589);
// → 79B
I used the below script to take a peek at available patters
$fmt = new NumberFormatter('en_US', NumberFormatter::DURATION);
var_dump($fmt->getPattern());
I've looked at
- NumberFormatter::PATTERN_DECIMAL
- NumberFormatter::DECIMAL
- NumberFormatter::CURRENCY
- NumberFormatter::PERCENT
- NumberFormatter::SCIENTIFIC
- NumberFormatter::SPELLOUT
- NumberFormatter::ORDINAL
None of them has the compact pattern.
Does anyone have a working code for PHP? Or, potentially, compact pattern is not currently supported?