formatn

Text formatting of Doubles


Keywords
development, library, text, Propose Tags, , Index, Quick Jump, Data.FormatN, formatn-0.3.0.1.tar.gz, browse, Package description, Package maintainers, tonyday567, edit package information , 0.1.0
License
BSD-3-Clause
Install
cabal install formatn-0.3.0.1

Documentation

formatn

https://img.shields.io/hackage/v/formatn.svg https://github.com/tonyday567/formatn/workflows/haskell-ci/badge.svg

A library for support of:

  • significant figure rounding of numbers, and
  • common number formatting patterns.

Usage

:reload
:set prompt "> "

:set -Wno-type-defaults
:set -XOverloadedStrings
import Data.FormatN

xs = [(-1),0,0.1,1,1.01,1.02,1.1,1.2]

fixed (Just 2) <$> xs
decimal (Just 2) <$> xs
formats False False (const DecimalStyle) (Just 2) xs
formats False True (const DecimalStyle) (Just 2) xs
distinguish 4 False True (const DecimalStyle) (Just 2) xs

getting 0 right

fixed

fixed (Just 3) <$> [0, 0.5, 1.5, 2.0]

fixed defaults to representing Doubles in the same manner as Haskell does ie with a trailing ‘.0’

fixed Nothing <$> [0, 0.5, 1.5, 2]

expt

expt Nothing 0
expt (Just 2) 1
expt (Just 2) 0

decimal

decimal Nothing 0
decimal (Just 1) 0
decimal (Just 3) 0

percent

percent is a little weird any way you cut it.

percent decimalSF (Just 4) 0
percent decimalSF (Just 4) 1

inclusion in lists

formats True False commaPrecStyle Nothing [0, 0.5, 1.5, 2]
formats True False commaPrecStyle (Just 1) [0, 1, 10]
formats True False commaPrecStyle (Just 1) [0, 0.5, 1.5, 2]
formats True False commaPrecStyle (Just 2) [0, 0.5, 1.5, 2]
formats True True commaPrecStyle (Just 6) [0, 0.5, 1.5, 2]