cuducos/elm-format-number/2.0.0

NOTE: this package is not compatible with Elm 0.19.1

FormatNumber

This simple package formats numbers as pretty strings. It is flexible enough to deal with different number of decimals, different thousand separators and diffetent decimal separator.

Locale

type alias Locale =
{ decimals : Int
, thousandSeparator : String
, decimalSeparator : String
}

Locale to configure the format options.

Usage

formatFloat : Locale -> Float -> String

Format a float number as a pretty string:

>>> formatFloat { decimals = 2, thousandSeparator = ",", decimalSeparator = "." } 1234.5567
"1,234.56"


>>> formatFloat (Locale 3 "." ",") -7654.3210
"-7.654,321"


>>> formatFloat (Locale 1 "," ".") -0.01
"0.0"
formatInt : Locale -> Int -> String

Format a integer number as a pretty string:

>>> formatInt { decimals = 1, thousandSeparator = ",", decimalSeparator = "." } 0
"0.0"


>>> formatInt (Locale 1 "," ".") 1234567890
"1,234,567,890.0"