Copyright | Soostone Inc |
---|---|
License | BSD3 |
Maintainer | libs@soostone.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Formatting for numeric values.
- 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
- nfUnits :: Lens' NumFormat Double
- nfPrefix :: Lens' NumFormat Text
- nfSuffix :: Lens' NumFormat Text
- nfThouSep :: Lens' NumFormat Text
- nfDecSep :: Lens' NumFormat Text
- nfStyle :: Lens' NumFormat NumStyle
- nfPrec :: Lens' NumFormat (Maybe (Int, PrecisionType))
- nfNegStyle :: Lens' NumFormat NegativeStyle
- rawIntFmt :: NumFormat
- intFmt :: NumFormat
- percentFmt :: NumFormat
- numFmt :: NumFormat
- usdFmt :: NumFormat
- formatPct :: Real a => Int -> a -> Text
- formatNum :: Real a => NumFormat -> a -> Text
- formatIntegral :: Integral a => NumFormat -> a -> Text
Documentation
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) |
Lenses
Common formats
percentFmt :: NumFormat Source
Common format for percentages. Example: 75.000%
Formatting functions
formatPct :: Real a => Int -> a -> Text Source
Convenience wrapper for percentages that lets you easily control the number of decimal places.
formatNum :: Real a => NumFormat -> a -> Text Source
This function checks to see if the number is smaller than the number of digits of precision being displayed and if so, switches to scientific notation.
formatIntegral :: Integral a => NumFormat -> a -> Text Source
This function checks to see if the number is smaller than the number of digits of precision being displayed and if so, switches to scientific notation.