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 6.0.1
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 6.0.1
Committed At 2018-07-12 10:51:42 UTC
myrho/elm-round 1.0.3 <= v < 2.0.0 1.0.4
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1

README

Elm Format Number Build Status

This simple Elm package formats float numbers as pretty strings:

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

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

It is flexible enough to deal with different number of decimals, different thousand separators, different decimal separator, and different ways to represent negative numbers — all that is possible using Locales.

Elm Format Number has a couple of predefined Locales and it is easy to customize your own:

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

sharesLocale : Locale
sharesLocale =
    { usLocale
        | decimals = 3
        , negativePrefix = "("
        , negativeSuffix = ")"
    }

format usLocale -pi -- "−3.14"
format sharesLocale -pi -- "(3.142)"

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

Tests

This package uses elm-verify-examples, all the examples in the documentation are automatically tested:

$ npm install
$ npm test