This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Format numbers as pretty strings
version 2.0.0
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 2.0.0
Committed At 2016-12-27 13:30:32 UTC
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1

Modules

README

Elm Format Number

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.

Usage

Creating a custom Locale

The 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 = "."
    }

From Float do String

formatFloat : Locale -> Float -> String

Format 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"

From Int do String

formatInt : Locale -> Int -> String

Format 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"

Tests

Requires elm-doc-test:

$ elm-doc-test
$ elm-test init
$ elm-test tests/Doc/Main.elm