cuducos/elm-format-number 2.0.0

Format numbers as pretty strings

Platform: Elm

Language: Elm

License: BSD-3-Clause

Repository: https://github.com/cuducos/elm-format-number

View on registry: http://package.elm-lang.org/packages/cuducos/elm-format-number/2.0.0

Direct download link: https://github.com/cuducos/elm-format-number/archive/2.0.0.zip

Install: elm-package install cuducos/elm-format-number 2.0.0


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 to 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

Dependencies Requirements Latest Stable Latest Release Licenses
elm-lang/core 5.0.0 <= v < 6.0.0 5.0.0 5.0.0 BSD-3-Clause
Explore the resolved dependency tree for cuducos/elm-format-number 2.0.0

Releases

  • 2.0.0 - December 28, 2016 01:00
  • 1.0.0 - December 17, 2016 04:57

Project Statistics

SourceRank 8
Dependencies 1
Dependent projects 0
Dependent repositories 0
Total releases 2
Latest release
First release
Stars 3
Forks 1
Watchers 1
Contributors 2
Repo Size: 8.79 KB

Top Contributors See all

Eduardo Cuducos Plínio Balduino

Something wrong with this page? Make a suggestion

Export .ABOUT file for this library

Last synced: 2017-01-21 01:01:28 UTC