This simple Elm package formats numbers as pretty strings. It is flexible enough to deal with different number of decimals, different thousand separators and diffetent decimal separator.
LocaleThe Locale is a type alias to hold all the information to format your strings. For example:
defaultLocale : Locale
defaultLocale =
{ decimals = 2
, thousandSeparator = ","
, decimalSeparator = "."
}
alternativeLocale : Locale
alternativeLocale =
{ decimals = 3
, thousandSeparator = "."
, decimalSeparator = ","
}
yetAnotherLocale : Locale
yetAnotherLocale =
{ decimals = 1
, thousandSeparator = ""
, decimalSeparator = "."
}Float do StringformatFloat : Locale -> Float -> StringFormat a Float number as a pretty string. For example, using the locales defined above:
formatFloat defaultLocale 1234.5567 == "1,234.56"
formatFloat alternativeLocale -7654.3210 == "-7.654,321"
formatFloat yetAnotherLocale -0.01 == "0.0"Int do StringformatInt : Locale -> Int -> StringFormat a Int number as a pretty string. For example, using the locales defined above:
formatInt defaultLocale 0 == "0.00"
formatInt defaultLocale 1234567890 == "1,234,567,890.0"Requires elm-doc-test:
$ elm-doc-test
$ elm-test init
$ elm-test tests/Doc/Main.elm