Hello all,
I've been investigating and trying to code a compact number format otherwise known as a short scale formatter or a humanizing big numbers into smaller ones in Swift.
I've been playing around with code I found on Stackoverflow; and in some instances they either rely on an array of keys/symbols without any boundary checking, or aren't complete, or aren't consistent in their formatting or results; or aren't localisable to different languages.
In my research, I found that Twitter, Javascript libraries, etc use/refer to the Unicode standard,
Unicode ICU 67.1 at:
https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/numberformatter_8h.html
And on the Mozilla site, the standard Intl.number format at:
Shows a way to get short formats:
console.log(new Intl.NumberFormat('en-GB', { notation: "compact" , compactDisplay: "short" }).format(987654321));
And, on the twitter github at:
https://github.com/twitter/twitter-cldr-js/blob/master/lib/assets/javascripts/twitter_cldr/es-US.js
They split up the short scale formats by locales and I think they use a pattern technique, as referred to by the Unicode standard at:
Given this, rather than trying to recode the wheel I was wondering whether it is possible to use the Unicode
standard to short scale numbers?
I've noticed that In the open-source code for Apple Swift on Github there is indeed a reference to compactdecimalformat.h
at:
But I don't know how to use it.
I'm wondering does anybody know how to call or use compactdecimalformat.h from the darwin library?
Alternatively, if there already is a framework or library that handles this kind of formatting; please let me know.
I did post a question on Stackoverflow about this, but perhaps the decided Swift forum can help or assist?