cuducos/elm-format-number

Format numbers as pretty strings


License
BSD-3-Clause
Install
elm-package install cuducos/elm-format-number 4.0.1

Contributors

Eduardo Cuducos Ophir LOJKINE Pedro Calderon Plínio Balduino Peter Gao


See all contributors


Documentation

Elm Format Number Build Status

This simple Elm package formats float numbers as pretty strings:

import FormatNumber exposing (format)
import FormatNumber.Locales exposing (spanishLocale)

format spanishLocale (pi * 1000)  -- "3.141,59"

It is flexible enough to deal with different number of decimals, different thousand separators and diffetent decimal separator. It has a couple os predefined Locale but you can edit them or create your own:

import FormatNumber exposing (format)
import FormatNumber.Locales exposing (Locale)

myLocale : Locale
myLocale =
    { decimals = 4
    , thousandSeparator = " "
    , decimalSeparator = "."
    }
    
sharesLocale : Locale
sharesLocale = { myLocale | decimals = 3 }

format myLocale (pi * 1000) -- "3 141.5926"
format sharesLocale (pi * 1000) -- "3 141.593"


The API is further documented in package.elm-lang.org.

Tests

This package uses elm-doc-test, all the exemples in the documentation are automatically tested:

$ yarn install
$ yarn test