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

CopyrightSoostone Inc
LicenseBSD3
Maintainerlibs@soostone.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Formattable.NumFormat

Contents

Description

Formatting for numeric values.

Synopsis

Documentation

data NumFormat Source

Constructors

NumFormat 

Fields

_nfUnits :: Double

Units 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 :: Text

A prefix to add to the number, commonly used for currency designation.

_nfSuffix :: Text

A suffix for the number. Percent, for example.

_nfThouSep :: Text

The character to use as thousands separator if applicable.

_nfDecSep :: Text

Character to use for the decimal separator.

_nfStyle :: NumStyle

The formatting style

_nfPrec :: Maybe (Int, PrecisionType)

Amount of precision to display

_nfNegStyle :: NegativeStyle

Styles for negative numbers

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

autoStyle :: NumStyle Source

A reasonable default value for NumStyle.

data PrecisionType Source

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.

data NegativeStyle Source

Different styles for representing negative numbers.

Constructors

NegMinusSign

Shows negative numbers as -123.000

NegParens

Shows negative numbers as (123.000)

Lenses

Common formats

rawIntFmt :: NumFormat Source

Int format with no thousands separator.

intFmt :: NumFormat Source

Int format with comma as the thousands separator.

percentFmt :: NumFormat Source

Common format for percentages. Example: 75.000%

numFmt :: NumFormat Source

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

usdFmt :: NumFormat Source

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

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.