TIP NumberPlugin is not installed on Foswiki.org.


Localized Number Formatter

This plugin allows to format

  • numbers,
  • currencies and
  • percentages

in a localized way using the Unicode CLDR.

For example, a number such as 1234 is formatted differently depending on the locales

Number Type Locale Parameter Output
1234.00 number en_US   1,234
    de_DE   1.234
    ar   ١٬٢٣٤
    es   1234
1234.00 currency en_US currency_code="USD" $1,234.00
  currency de_DE currency_code="EUR" 1.234,00 €
  currency ar currency_code="AED" د.إ.‏ ١٬٢٣٤٫٠٠
  currency ar currency_code="USD" US$ ١٬٢٣٤٫٠٠
  currency es currency_code="EUR" 1234,00 €
0.1234 percent en_US   12%
    de_DE   12 %
    ar   ١٢٪
    es   12 %
    en_US minimum_fraction_digits="1" 12.3%


By default, numbers are formatted by the %NUMBER{"value" param="..."}% macro

Parameter Description Default
type specifies what kind of number this is and will use the related formatter for it, can be number, currency or percent number
locale unicode locale identifiers, for example es (Spanish), es_ES (European Spanish), es_419 (Latin American Spanish), zh_Hant (Traditional Chinese), zh_Hans (Simplified Chinese), chr (Cherokee) current locale of the user's session
decimal_sign delimiter of fraction see current locale
group_sign delimiter every three digits in large numbers see current locale
plus_sign example + see current locale
minus_sign - see current locale
infinity see current locale
nan NaN see current locale
pattern pattern how to format a number, for example #,##0.### see current locale
minimum_integer_digits   see current locale
Parameters for currency:
currency_code this parameter is required when the type is set to currency; possible values are any 3-letter digits according to ISO 4217, such as EUR or USD  
currency_sign the sign that is used to identify the currency see current locale
cash for boolean switch to enable rendering of cache which may be formatted differently for some locales 0
Parameters for percent:
permil   0
percent_sign   %

Further documentation is available at CLDR::Number, the perl library being used underneath.

In addition to the %NUMBER macro you may specify a list of currency codes as a shortcut for the given type of number. The configuration setting stored in $Foswiki::cfg{NumberPlugin}{Currencies} will specify the list of those which a macro should be created for. For example a setting such as

$Foswiki::cfg{NumberPlugin}{Currencies} = "EUR, USD";

will create the macros %EUR{...}% and %USD{...}% as a shortcut for

%NUMBER{"..." type="currency" currency_code="<code>"}%

Formfield types

This plugin defines three additional formfield types that may be used defining DataForms.

  • currency
  • number
  • percent

Parameters are specified in the Values column of the formfield, i.e. currency requires a currency_code parameter such as in:

| *Name*           | *Type*   | *Size* | *Values*            | *Description* | *Attributes* | *Default* |
| Advance Payments | currency | 30     | currency_code="eur" |               |              | 0         |

Installation Instructions

You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.

Open configure, and open the "Extensions" section. Use "Find More Extensions" to get a list of available extensions. Select "Install".

If you have any problems, or if the extension isn't available in configure, then you can still install manually from the command-line. See http://foswiki.org/Support/ManuallyInstallingExtensions for more help.



Change History

03 Jan 2017 initial release
Topic attachments
I Attachment Action Size Date Who Comment
NumberPlugin.md5md5 NumberPlugin.md5 manage 159 bytes 03 Jan 2017 - 17:32 MichaelDaum  
NumberPlugin.sha1sha1 NumberPlugin.sha1 manage 183 bytes 03 Jan 2017 - 17:32 MichaelDaum  
NumberPlugin.tgztgz NumberPlugin.tgz manage 7 K 03 Jan 2017 - 17:32 MichaelDaum  
NumberPlugin.zipzip NumberPlugin.zip manage 12 K 03 Jan 2017 - 17:32 MichaelDaum  
NumberPlugin_installerEXT NumberPlugin_installer manage 4 K 03 Jan 2017 - 17:32 MichaelDaum  
Topic revision: r1 - 03 Jan 2017, MichaelDaum - This page was cached on 01 Jun 2017 - 21:46.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License