formatn-0.0.1: Number text formatting.
Safe HaskellNone
LanguageHaskell2010

Data.FormatN

Description

Formatting of Doubles.

Synopsis

Documentation

data FormatN Source #

Wrapper for the various formatting options.

>>> defaultFormatN
FormatComma 2

Instances

Instances details
Eq FormatN Source # 
Instance details

Defined in Data.FormatN

Methods

(==) :: FormatN -> FormatN -> Bool #

(/=) :: FormatN -> FormatN -> Bool #

Show FormatN Source # 
Instance details

Defined in Data.FormatN

Generic FormatN Source # 
Instance details

Defined in Data.FormatN

Associated Types

type Rep FormatN :: Type -> Type #

Methods

from :: FormatN -> Rep FormatN x #

to :: Rep FormatN x -> FormatN #

type Rep FormatN Source # 
Instance details

Defined in Data.FormatN

defaultFormatN :: FormatN Source #

The official format

fromFormatN :: IsString s => FormatN -> s Source #

type textifier

toFormatN :: (Eq s, IsString s) => s -> Int -> FormatN Source #

type readifier

fixed :: Int -> Double -> Text Source #

to x decimal places

>>> fixed 2 1
"1.00"
>>> fixed 2 0.001
"0.00"

decimal :: Int -> Double -> Text Source #

round to n significant figures and always use decimal notation

>>> decimal 2 0.000001234
"0.00000123"
>>> decimal 2 1234567
"1230000"

prec :: Int -> Double -> Text Source #

format numbers between 0.001 and 1,000,000 using digit and comma notation and exponential outside this range, with x significant figures.

>>> prec 1 0.00234
"0.0023"
>>> prec 1 0.000023
"2.3e-5"
>>> prec 1 123
"120"
>>> prec 1 123456
"120000"
>>> prec 1 1234567
"1.2e6"

comma :: Int -> Double -> Text Source #

add commas format for numbers above 1,000 but below 1 million, otherwise use prec.

>>> comma 2 1234
"1,230"

expt :: Int -> Double -> Text Source #

scientific exponential

>>> expt 2 1234
"1.23e3"

dollar :: Int -> Double -> Text Source #

dollars and cents, always decimal notation

>>> dollar 2 1234
"$1,230"
>>> dollar 2 0.01234
"$0.0123"

formatN :: FormatN -> Double -> Text Source #

make text

precision :: (Int -> Double -> Text) -> Int -> [Double] -> [Text] Source #

Provide formatted text for a list of numbers so that they are just distinguished. 'precision commas 2 ticks' means use as much precision as is needed for them to be distinguished, but with at least 2 significant figures.

formatNs :: FormatN -> [Double] -> [Text] Source #

Consistently format a list of doubles.