![]() |
Abbreviated numbers |
Showing big numbers to a user might have problems. The first one is that they tend to be hard to read, especially when the digits get longer than 5. In addition, a long number takes space that might be limited. To avoid these issues, we can use abbreviated numbers. The following table contains some numbers and their abbreviated versions in English, Finnish, and Japanese:
| Number | English short | English long | Finnish short | Finnish long | Japanese |
|---|---|---|---|---|---|
| 19 | 19 | 19 | 19 |
19 |
19 |
| 1000 | 1K | 1 thousand | 1 t. | 1 tuhat | 1000 |
| 25000 | 25K | 25 thousand | 25 t. | 25 tuhatta | 2.5万 |
| 1 200 000 | 1.2M | 1.2 million | 1,2 milj. | 1,2 miljoonaa | 120万 |
| 34 000 000 | 34M | 34 million | 34 milj. | 34 miljoonaa | 3400万 |
| 2 000 000 000 | 2G | 2 billion | 2 mrd. | 2 miljardia | 20億 |
As you can see, the abbreviate rules differ a lot, depending on the language. Some cultures use 1000 as a separator (used in Europe), some cultures use 10 000 (e.g., Japan). Some languages use single-letter abbreviations, and some use longer.
AbbreviatedNumber.Format(form, number): string;
It takes two parameters: form (short or long abbreviation) and number, and returns a string.
Hardly any platform contains built-in support for abbreviated numbers. Most platforms require that you use our custom API. The API source code is available in GitHub. The following table shows how various platforms support the ordinal numbers:
| Platforms | Status | APIs | Samples |
|---|---|---|---|
| .NET Standard | yes | <data-dir>\Library\NET\Number.cs | <data-dir>\Samples\ASP.NET\Number |
| Android | yes | <data-dir>\Library\Java\Number.java | |
| Angular | yes | <data-dir>\Library\Angular\number.pipe.ts | <data-dir>\Samples\Angular\Number |
| Delphi | yes | <data-dir>\Library\Delphi\NtNumber.pas | <data-dir>\Samples\Delphi\VCL\Number <data-dir>\Samples\Delphi\FMX\Number |
| Java | yes | <data-dir>\Library\Java\Number.java | |
| JavaScript | yes | <data-dir>\Library\JavaScript\number.js | |
| TypeScript | yes | <data-dir>\Library\TypeScript\number.ts | See the Angular sample |
yes means that we have implemented an open-source API. To use it, include the API file in your project. The samples in <data-dir>\Samples\<platform> show how to use the API.
built-in means that the standard API of the platform supports the feature. The platforms that use ICU MessageFormat, such as Angular, Flutter, React Intl, and svelte-i18n, support the same plural, select, and nested patterns as Soluling's API. Other platforms support plurals and sometimes genders, but not select or multiple parameters. If neither the platform nor our APIs support a feature, you can write your own API based on one of ours.