chart-svg-0.2.2: Charting library targetting SVGs.
Safe HaskellNone
LanguageHaskell2010

Data.FormatN

Description

Formatting of numeric values.

Synopsis

Documentation

data FormatN Source #

Number formatting options.

>>> defaultFormatN
FormatComma (Just 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 #

textifier

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

readifier

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

to x decimal places

>>> fixed (Just 2) 1
"1.00"
>>> fixed (Just 2) 0.001
"0.00"

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

round to n significant figures and always use decimal notation >>> decimal (Just 2) 0.000001234 "0.00000123"

>>> decimal (Just 2) 1234567
"1230000"

prec :: Maybe 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 (Just 1) 0.00234 "0.0023"

prec (Just 1) 0.000023

"2.3e-5"

prec (Just 1) 123

"120"

prec (Just 1) 123456

"120,000"

>>> prec (Just 1) 1234567
"1.2e6"

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

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

>>> comma Nothing 1234.567
"1,234.567"
>>> comma (Just 2) 1234
"1,230"

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

scientific exponential

>>> expt (Just 2) 1234
"1.23e3"

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

dollars and cents, always decimal notation

>>> dollar (Just 2) 1234
"$1,230"
>>> dollar (Just 2) 0.01234
"$0.0123"

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

make text

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

Provide formatted text for a list of numbers so that they are just distinguished. 'precision commas (Just 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.

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

Format with the shorter of show and formatN.