formattable-0.1.1: Business-quality formatting of numbers, dates, and other things

Formattable.NumFormat

Description

Formatting for numeric values.

Synopsis

# 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.

data NumFormat Source

The main data structure with all the necessary information for formatting numbers.

Constructors

 NumFormat Fields_nfUnits :: DoubleUnits of measure to use in formatting the number. This is useful for things like percentages where you would use (units of 0.01) or financial statements (units of 1000 for example)._nfPrefix :: TextA prefix to add to the number, commonly used for currency designation._nfSuffix :: TextA suffix for the number. Percent, for example._nfThouSep :: TextThe character to use as thousands separator if applicable._nfDecSep :: TextCharacter to use for the decimal separator._nfStyle :: NumStyleThe formatting style_nfPrec :: Maybe (Int, PrecisionType)Amount of precision to display_nfNegStyle :: NegativeStyleStyles for negative numbers

Instances

 Eq NumFormat Show NumFormat Default NumFormat Typeable * NumFormat

data NumStyle Source

Data structure describing available styles of number formatting.

Constructors

 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.

Instances

 Eq NumStyle Show NumStyle

A reasonable default value for NumStyle.

Data structure for different methods of specifying precision.

Constructors

 SigFigs Specifies precision as a fixed number of significant digits Decimals Specifies precision with a fixed number of digits after the decimal place.

Instances

 Eq PrecisionType Show PrecisionType

Different styles for representing negative numbers.

Constructors

 NegMinusSign Shows negative numbers as -123.000 NegParens Shows negative numbers as (123.000)

Instances

 Eq NegativeStyle Show NegativeStyle

# Common formats

Int format with no thousands separator.

Int format with comma as the thousands separator.

Common format for percentages. Example: 75.000%

Common format for generic numeric quantities of the form 123,456.99.

Common format for US dollar quantities of the form \$123,456.99.

# Other formatting functions

Arguments

 :: 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.