Skip to content

Latest commit

 

History

History
51 lines (31 loc) · 1.97 KB

README.md

File metadata and controls

51 lines (31 loc) · 1.97 KB

nmbr-icu (a fork of nmbr)

CI Status Version License Platform

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.

Installation

nmbr is available through SPM. To install it, simply add the package to your dependencies.

Usage

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"

Updating the version of ICU

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.

License

nmbr-icu is available under the MIT license. See the LICENSE file for more info.