This page is protected against editing.

Template:Formatnum

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search


Protected This template has been protected from editing to prevent vandalism.
Please discuss changes on the talk page or request unprotection.
Template documentationview · edit · history · purge ]
This documentation is transcluded from Template:Formatnum/doc.

This template formats a number in the local format (local numerals, local thousands separator, decimal separator and the pattern of separators [some languages for example have a ten-thousands separator]) of the user's preferred language.

Usage

{{Formatnum |1= |2= |sep= |prec= }}

Template parameters

ParameterDescriptionDefaultStatus
1
number
numberNumber that shall be formatted in local format (must be unformatted [without thousands separators])emptyrequired
2
lang
languageLanguage code (only needs to be provided if the language shall be fixed and independent from the user's preferences){{int:lang}}optional
sepwithout thousands separatorsSet to any non-empty value to remove thousands separators (e.g. for dates)emptyoptional
precprecisionDecimal place, minimal number of bytes behind the decimal point to show (valid range: 0–14). This needs to be set if zeros at the end of the number shall be visible (otherwise e.g. 0.100 will be converted to 0.1)emptyoptional
Template data
<templatedata>JSON</templatedata> ./. {{TemplateBox}}
TemplateData

TemplateData is a way to store information about template parameters (the description of those and of the whole template) for both humans and machines. It is used by VisualEditor and possibly other tools like Upload Wizard.


Existing template documentation
At Wikimedia Commons, it is recommended to use {{TemplateBox}} with either ‎useTemplateData=1 or ‎useTemplateData=only on the ‎/doc subpage and transcluding it with {{Documentation}} into the template. ‎<nowiki>-tags can be wrapped around the arguments, if required, to avoid templates being expanded.

Newly created template documentation and imports
Another option, especially for imported templates, or for users with JSON experience, is placing raw ‎<templatedata>-tags into the Wikitext of the template, as described in various Wikipediae.

Discussion
There is an ongoing discussion about that matter. Feel invited to comment if you are experienced in either way, your time permits and if you like to share your opinion or to make a suggestion.


Wikipedia's help about TemplateDataCommons-specific information

This template formats a number in the local format (local numerals, local thousands separator, decimal separator and the pattern of separators [some languages for example have a ten-thousands separator]) of the user's preferred language.

Template parameters[Edit template data]

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
number1 number

Number that shall be formatted in local format (must be unformatted [without thousands separators])

Linerequired
language2 lang

Language code (only needs to be provided if the language shall be fixed and independent from the user's preferences)

Default
{{int:lang}}
Lineoptional
precisionprec

Decimal place, minimal number of bytes behind the decimal point to show (valid range: 0–14). This needs to be set if zeros at the end of the number shall be visible (otherwise e.g. 0.100 will be converted to 0.1)

Numberoptional
without thousands separatorssep

Set to any non-empty value to remove thousands separators (e.g. for dates)

Lineoptional

Additional information

The template is intended to be used in the following namespaces: the Template namespace

The template is intended to be used by the following user groups: all users

Relies on:
Module:Formatnum

Localization

This template is not intended to be localized.

Internationalization is made using MediaWiki's built-in number formatter (except for some languages not yet supported in MediaWiki).

Examples

  • {{formatnum|100000}} → 100,000
  • {{formatnum|100000|sep=0}} → 100,000
  • {{formatnum|100000|sep=no}} → 100,000
  • {{formatnum|12345.67}} → 12,345.67
  • {{formatnum|-102}} → −102
  • {{formatnum|1234567890|ar}} → ١٬٢٣٤٬٥٦٧٬٨٩٠

Remark

  • It is not compatible with tables sorting. The value is not detected as a number.