text-icu-0.8.0.3: Bindings to the ICU library
Copyright(c) 2021 Torsten Kemps-Benedix
LicenseBSD-style
Maintainerbos@serpentine.com
Stabilityexperimental
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.Text.ICU.NumberFormatter

Description

Number formatter implemented as bindings to the International Components for Unicode (ICU) libraries.

Synopsis

Data

Formatter

numberFormatter :: Text -> LocaleName -> IO NumberFormatter Source #

Create a new NumberFormatter.

See https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html for how to specify the number skeletons. And use availableLocales in order to find the allowed locale names. These usuallly look like "en", "de", "de_AT" etc. See formatIntegral and formatDouble for some examples.

Here are some examples for number skeletons, see https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#examples for more:

Long SkeletonConcise Skeleton | Inputen-US OutputComments
percent .00 percent .00 scale/100 percent scale/100 measure-unit/length-meter unit-width-full-name compact-short compact-long group-min2 group-min2 sign-always sign-always sign-except-zero sign-except-zero% | 25 .00 | 25 % .00 | 25 scale/100 | 0.3 %x100 | 0.3 unit/meter | 5 unit/meter | 5 K | 5000 KK | 5000 ,? | 5000 ,? | 15000 +! | 60 +! | 0 +? | 60 +? | 025% 25.00 25.00% 30 30% 5 m 5 meters 5K 5 thousand 5000 15,000 +60 +0 +60 0 Equivalent to Precision::fixedFraction(2) Multiply by 100 before formatting UnitWidth defaults to Short Require 2 digits in group for separator Show sign on all numbers Show sign on all numbers except 0

formatIntegral :: Integral a => NumberFormatter -> a -> Text Source #

Format an integral number.

See https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html for how to specify the number skeletons.

>>> import Data.Text
>>> nf <- numberFormatter (pack "precision-integer") (Locale "de")
>>> formatIntegral nf 12345
"12.345"
>>> nf2 <- numberFormatter (pack "precision-integer") (Locale "fr")
>>> formatIntegral nf2 12345
"12\8239\&345"

formatIntegral' :: Integral a => Text -> LocaleName -> a -> Text Source #

Create a number formatter and apply it to an integral number.

formatDouble :: NumberFormatter -> Double -> Text Source #

Format a Double.

See https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html for how to specify the number skeletons.

>>> import Data.Text
>>> nf3 <- numberFormatter (pack "precision-currency-cash") (Locale "it")
>>> formatDouble nf3 12345.6789
"12.345,68"

formatDouble' :: Text -> LocaleName -> Double -> Text Source #

Create a number formatter and apply it to a Double.