Skip to content

jweir/elm-format-number

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

✨Format numbers as pretty strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elm 100.0%