Safe Haskell | None |
---|---|
Language | Haskell2010 |
Formatting of numeric values.
Synopsis
- data FormatN
- = FormatFixed (Maybe Int)
- | FormatDecimal (Maybe Int)
- | FormatComma (Maybe Int)
- | FormatExpt (Maybe Int)
- | FormatPrec (Maybe Int)
- | FormatDollar (Maybe Int)
- | FormatPercent (Maybe Int)
- | FormatNone
- defaultFormatN :: FormatN
- fromFormatN :: IsString s => FormatN -> s
- toFormatN :: (Eq s, IsString s) => s -> Maybe Int -> FormatN
- fixed :: Maybe Int -> Double -> Text
- decimal :: Maybe Int -> Double -> Text
- prec :: Maybe Int -> Double -> Text
- comma :: Maybe Int -> Double -> Text
- expt :: Maybe Int -> Double -> Text
- dollar :: Maybe Int -> Double -> Text
- percent :: Maybe Int -> Double -> Text
- formatN :: FormatN -> Double -> Text
- precision :: (Maybe Int -> Double -> Text) -> Maybe Int -> [Double] -> [Text]
- formatNs :: FormatN -> [Double] -> [Text]
- showOr :: FormatN -> Double -> Text
- roundSig :: Int -> Double -> Scientific
Documentation
Number formatting options.
>>>
defaultFormatN
FormatComma (Just 2)
FormatFixed (Maybe Int) | |
FormatDecimal (Maybe Int) | |
FormatComma (Maybe Int) | |
FormatExpt (Maybe Int) | |
FormatPrec (Maybe Int) | |
FormatDollar (Maybe Int) | |
FormatPercent (Maybe Int) | |
FormatNone |
Instances
defaultFormatN :: FormatN Source #
The official format
fromFormatN :: IsString s => FormatN -> s Source #
textifier
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"
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"
percent :: Maybe Int -> Double -> Text Source #
fixed percent, always decimal notation
>>>
percent (Just 2) 0.001234
"0.123%"
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.