myrho/numeral-elm/1.0.1

NOTE: the latest version is 1.0.2

numeral-elm

Fork of ggb/numeral-elm at 1.5.0 with fixes by soad003 since the original package seems to be unmaintained. Original README continues from here.

Elm module for (advanced) number formatting. It is a direct port of Numeral.js and it is possible to use the same format strings. Manipulation and unformatting of numbers is not yet supported.

If you create a new language-file, please let me know or send a pull request.

Formatting

Format a number with a given language.

import Languages.Japanese as Japanese

myFormat = formatWithLanguage Japanese.lang "0.0a"

-- map myFormat [10123.12, 235798239.3242] == ["10.1千","235.8百万"]

The format-function works the same way as formatWithLanguage, but English is set as default language.

format "$0,0.00" 1000.234 == "$1,000.23"

Numbers

NumberFormatResult
10000'0,0.0000'10,000.0000
10000.23'0,0'10,000
10000.23'+0,0'+10,000
-10000'0,0.0'-10,000.0
10000.1234'0.000'10000.123
10000.1234'0[.]00000'10000.12340
-10000'(0,0.0000)'(10,000.0000)
-0.23'.00'-.23
-0.23'(.00)'(.23)
0.23'0.00000'0.23000
0.23'0.0[0000]'0.23
1230974'0.0a'1.2m
1460'0 a'1 k
-104000'0a'-104k
1'0o'1st
52'0o'52nd
23'0o'23rd
100'0o'100th

Currency

NumberFormatResult
1000.234'$0,0.00'$1,000.23
1000.2'0,0[.]00 $'1,000.20 $
1001'$ 0,0[.]00'$ 1,001
-1000.234'($0,0)'($1,000)
-1000.234'$0.00'-$1000.23
1230974'($ 0.00 a)'$ 1.23 m

Bytes

NumberFormatResult
100'0b'100B
2048'0 b'2 KB
7884486213'0.0b'7.3GB
3467479682787'0.000 b'3.154 TB

Percentages

NumberFormatResult
1'0%'100%
0.974878234'0.000%'97.488%
-0.43'0 %'-43 %
0.43'(0.000 %)'43.000 %

Time

NumberFormatResult
25'00:00:00'0:00:25
238'00:00:00'0:03:58
63846'00:00:00'17:44:06

Custom Unit Suffixes

NumberFormatResult
123450,0[ pcs.]12,345 pcs.
123450,0[pcs.]12,345pcs.
3000000,0 [ ponies]300,000 ponies