text-icu-0.8.0.5: Bindings to the ICU library

Copyright | (c) 2020 Torsten Kemps-Benedix
License | BSD-style
Maintainer | tkx68@icloud.com
Stability | experimental
Portability | GHC
Safe Haskell | None
Language | Haskell98

Data.Text.ICU.Number

Contents

- Unicode number formatting API

Description

New users with are strongly encouraged to see if Data.Text.ICU.NumberFormatter fits their use case. Although not deprecated, this header is provided for backwards compatibility only.

Synopsis

- numberFormatter :: NumberFormatStyle -> LocaleName -> NumberFormat
- class FormattableNumber n
- formatNumber :: FormattableNumber n => NumberFormat -> n -> Text
- formatNumber' :: FormattableNumber n => NumberFormatStyle -> LocaleName -> n -> Text
- data NumberFormatStyle
  - = NUM_PATTERN_DECIMAL Text
  - | NUM_DECIMAL
  - | NUM_CURRENCY
  - | NUM_PERCENT
  - | NUM_SCIENTIFIC
  - | NUM_SPELLOUT
  - | NUM_ORDINAL
  - | NUM_DURATION
  - | NUM_NUMBERING_SYSTEM
  - | NUM_PATTERN_RULEBASED Text
  - | NUM_CURRENCY_ISO
  - | NUM_CURRENCY_PLURAL
  - | NUM_CURRENCY_ACCOUNTING
  - | NUM_CASH_CURRENCY
  - | NUM_DECIMAL_COMPACT_SHORT
  - | NUM_DECIMAL_COMPACT_LONG
  - | NUM_CURRENCY_STANDARD
  - | NUM_FORMAT_STYLE_COUNT
  - | NUM_DEFAULT
  - | NUM_IGNORE
- data NumberFormat

# Unicode number formatting API

This module helps you to format and parse numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal. There are different number format styles like decimal, currency, percent and spelled-out.

Use `formatter` to create a formatter and `format` to format numbers.

numberFormatter Source #

Arguments

:: NumberFormatStyle | The type of number format to open. If NUM_PATTERN_DECIMAL or NUM_PATTERN_RULEBASED is passed then the number format is opened using the given pattern, which must conform to the syntax described in DecimalFormat or RuleBasedNumberFormat, respectively.
-> LocaleName | A locale identifier to use to determine formatting and parsing conventions, or NULL to use the default locale, e.g. "de_DE".
-> NumberFormat |

Create and return a new NumberFormat for formatting and parsing numbers.

A NumberFormat may be used to format numbers by calling unum_format, and to parse numbers by calling unum_parse. The caller must call unum_close when done to release resources used by this object.

class FormattableNumber n Source #

Format an integer using a NumberFormat.

The integer will be formatted according to the UNumberFormat's locale.

Minimal complete definition

formatNumber

#### Instances

Instances details

FormattableNumber Integer Source # |
Instance details Defined in Data.Text.ICU.Number Methods formatNumber :: NumberFormat -> Integer -> Text Source #
FormattableNumber Natural Source # |
Instance details Defined in Data.Text.ICU.Number Methods formatNumber :: NumberFormat -> Natural -> Text Source #
FormattableNumber Double Source # |
Instance details Defined in Data.Text.ICU.Number Methods formatNumber :: NumberFormat -> Double -> Text Source #
FormattableNumber Float Source # |
Instance details Defined in Data.Text.ICU.Number Methods formatNumber :: NumberFormat -> Float -> Text Source #
FormattableNumber Int Source # |
Instance details Defined in Data.Text.ICU.Number Methods formatNumber :: NumberFormat -> Int -> Text Source #

formatNumber Source #

Arguments

:: FormattableNumber n |
=> NumberFormat | The formatter to use.
-> n | The number to format.
-> Text |

formatNumber' Source #

Arguments

:: FormattableNumber n |
=> NumberFormatStyle | The type of number format to open. If NUM_PATTERN_DECIMAL or NUM_PATTERN_RULEBASED is passed then the number format is opened using the given pattern, which must conform to the syntax described in DecimalFormat or RuleBasedNumberFormat, respectively.
-> LocaleName | A locale identifier to use to determine formatting and parsing conventions, or NULL to use the default locale, e.g. "de_DE".
-> n | The number to format.
-> Text |

Create a formatter and apply it in one step.

data NumberFormatStyle Source #

The possible number format styles.

Constructors

NUM_PATTERN_DECIMAL Text | Decimal format defined by a pattern string. See the section "Patterns" at https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classDecimalFormat.html#Patterns for further details regarding pattern strings.
NUM_DECIMAL | Decimal format ("normal" style).
NUM_CURRENCY | Currency format (generic). Defaults to UNUM_CURRENCY_STANDARD style (using currency symbol, e.g., "$1.00", with non-accounting style for negative values e.g. using minus sign). The specific style may be specified using the -cf- locale key.
NUM_PERCENT | Percent format.
NUM_SCIENTIFIC | Scientific format.
NUM_SPELLOUT | Spellout rule-based format. The default ruleset can be specified/changed using unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS.
NUM_ORDINAL | Ordinal rule-based format. The default ruleset can be specified/changed using unum_setTextAttribute with UNUM_DEFAULT_RULESET; the available public rulesets can be listed using unum_getTextAttribute with UNUM_PUBLIC_RULESETS.
NUM_DURATION | Duration rule-based format.
NUM_NUMBERING_SYSTEM | Numbering system rule-based format.
NUM_PATTERN_RULEBASED Text | Rule-based format defined by a pattern string. See the section "Patterns" at https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classDecimalFormat.html#Patterns for further details regarding pattern strings.
NUM_CURRENCY_ISO | Currency format with an ISO currency code, e.g., "USD1.00".
NUM_CURRENCY_PLURAL | Currency format with a pluralized currency name, e.g., "1.00 US dollar" and "3.00 US dollars".
NUM_CURRENCY_ACCOUNTING | Currency format for accounting, e.g., "($3.00)" for negative currency amount instead of "-$3.00" (UNUM_CURRENCY). Overrides any style specified using -cf- key in locale.
NUM_CASH_CURRENCY | Currency format with a currency symbol given CASH usage, e.g., "NT$3" instead of "NT$3.23".
NUM_DECIMAL_COMPACT_SHORT | Decimal format expressed using compact notation (short form, corresponds to UNumberCompactStyle=UNUM_SHORT) e.g. "23K", "45B"
NUM_DECIMAL_COMPACT_LONG | Decimal format expressed using compact notation (long form, corresponds to UNumberCompactStyle=UNUM_LONG) e.g. "23 thousand", "45 billion"
NUM_CURRENCY_STANDARD | Currency format with a currency symbol, e.g., "$1.00", using non-accounting style for negative values (e.g. minus sign). Overrides any style specified using -cf- key in locale.
NUM_FORMAT_STYLE_COUNT | One more than the highest normal UNumberFormatStyle value. Deprecated: ICU 58 The numeric value may change over time, see ICU ticket #12420.
NUM_DEFAULT | Default format.
NUM_IGNORE | Alias for NUM_PATTERN_DECIMAL.

#### Instances

Instances details

Show NumberFormatStyle Source # |
Instance details Defined in Data.Text.ICU.Number Methods showsPrec :: Int -> NumberFormatStyle -> ShowS Source # show :: NumberFormatStyle -> String Source # showList :: [NumberFormatStyle] -> ShowS Source #
Eq NumberFormatStyle Source # |
Instance details Defined in Data.Text.ICU.Number Methods (==) :: NumberFormatStyle -> NumberFormatStyle -> Bool Source # (/=) :: NumberFormatStyle -> NumberFormatStyle -> Bool Source #

data NumberFormat Source #

This is the number formatter. It can be created with `formatter`. Use it to format numbers with the `format` function.