This pod is a (hopefully) very small library to short format numbers like this: http://cldr.unicode.org/translation/numbers-currency/number-patterns#TOC-Compact-decimal-formatting-Short-Numbers.
It's main purpose is for formatting pricing information (though it will format any number) - for example 1,100,000 would become £1.1M in en_GB, but would become £110万 in ja_JP.
It should
- deal with localisation (i.e. some locales group by 4 digits, not 3)
- deal with pricing correctly (i.e. put the right currency symbol in the right place)
- deal with long/short versions i.e. 1M vs. 1 million.
Long term, this should just be handled in Foundation
- there shouldn't really be a need for this pod.
nmbr is available through SPM. To install it, simply add the package to your dependencies.
Create a NMBRFormatter
let formatter = NMBRFormatter(locale: Locale(identifier: "en_GB"), maxPrecision: 0, notation: .short, currencyCode: "GBP")
Use the formatter
myLabel.text = formatter.string(from: 123.456) // "£123.46"
To update the ICU version, open the Makefile and update the ICU_tag
flag. It should be set to a value that is a released version of ICU. Then run:
make deepclean
gmake
If you do not have gmake
installed, install it with homebrew.
The file filters.json
contains a list of excluded features that helps make the data built by ICU smaller.
nmbr-icu is available under the MIT license. See the LICENSE file for more info.