Copyright | Soostone Inc |
---|---|
License | BSD3 |
Maintainer | libs@soostone.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Formatting for numeric values.
- formatNum :: Real a => NumFormat -> a -> Text
- formatIntegral :: Integral a => NumFormat -> a -> Text
- formatPct :: Real a => Int -> a -> Text
- data NumFormat = NumFormat {
- _nfUnits :: Double
- _nfPrefix :: Text
- _nfSuffix :: Text
- _nfThouSep :: Text
- _nfDecSep :: Text
- _nfStyle :: NumStyle
- _nfPrec :: Maybe (Int, PrecisionType)
- _nfNegStyle :: NegativeStyle
- data NumStyle
- autoStyle :: NumStyle
- data PrecisionType
- data NegativeStyle
- rawIntFmt :: NumFormat
- intFmt :: NumFormat
- percentFmt :: NumFormat
- numFmt :: NumFormat
- usdFmt :: NumFormat
- nfUnits :: Lens NumFormat NumFormat Double Double
- nfPrefix :: Lens NumFormat NumFormat Text Text
- nfSuffix :: Lens NumFormat NumFormat Text Text
- nfThouSep :: Lens NumFormat NumFormat Text Text
- nfDecSep :: Lens NumFormat NumFormat Text Text
- nfStyle :: Lens NumFormat NumFormat NumStyle NumStyle
- nfPrec :: Lens NumFormat NumFormat (Maybe (Int, PrecisionType)) (Maybe (Int, PrecisionType))
- nfNegStyle :: Lens NumFormat NumFormat NegativeStyle NegativeStyle
- formatNumGeneric :: Real a => (Maybe Int -> Double -> Text) -> (Maybe Int -> Double -> Text) -> NumFormat -> a -> Text
Main number formatting functions and data types
formatNum :: Real a => NumFormat -> a -> Text Source
Primary function for formatting floating point numbers.
formatIntegral :: Integral a => NumFormat -> a -> Text Source
Primary function for formatting integrals. This was originally created to avoid depending on the double-conversion package which uses a C library and is therefore less portable. We're keeping this as a separate function because it should have the potential to be more efficient than the floating point version.
formatPct :: Real a => Int -> a -> Text Source
Convenience wrapper for percentages that lets you easily control the number of decimal places.
The main data structure with all the necessary information for formatting numbers.
NumFormat | |
|
Data structure describing available styles of number formatting.
Exponent | Format with scientific notation |
Fixed | Format with standard decimal notation |
SmartExponent Int Int | The aruments a and b define bounds. If the absolute value of the number is in the interval [10 ^ a, 10 ^ b], then it uses the Fixed style. If the number is outside this interval, then use the Exponent style. |
SIStyle | Adds the symbol for the closest smaller SI prefix as the suffix to the formatted number. This suffix appears before any other suffix you designate. |
SmartSI Double Double | Like SIStyle but only applies the SI prefix if the number to be formatted falls within the range [a,b] given by the SmartSI arguments. |
data PrecisionType Source
Data structure for different methods of specifying precision.
data NegativeStyle Source
Different styles for representing negative numbers.
NegMinusSign | Shows negative numbers as -123.000 |
NegParens | Shows negative numbers as (123.000) |
Common formats
percentFmt :: NumFormat Source
Common format for percentages. Example: 75.000%
Lenses
nfPrec :: Lens NumFormat NumFormat (Maybe (Int, PrecisionType)) (Maybe (Int, PrecisionType)) Source
Other formatting functions
:: Real a | |
=> (Maybe Int -> Double -> Text) | Exponential formatter |
-> (Maybe Int -> Double -> Text) | Fixed formatter |
-> NumFormat | Format specification |
-> a | The number to format |
-> Text |
Generic floating point formatting function that allows you to specify your own underlying functions for formatting exponential and fixed formats. This can allow you to use more efficient versions if available. We also use it the test suite to check behavior against the old double-conversion implementation.