Jump to content

Module:Formatnum/doc: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
TFD closed as keep (XFDcloser)
Expand
Line 1: Line 1:
This module provides a number formatting functions. These functions can be used from #invoke or from other Lua modules.
This module is used by [[Module:Complex date]].

This module is used by [[Module:Complex date]] and {{tl|FXConvert}}

== Use from other Lua modules ==
To use the module from normal wiki pages, no special preparation is needed. If you are using the module from another Lua module, first you need to load it, like this:

<syntaxhighlight lang="lua">
local mf = require('Module:Formatnum')
</syntaxhighlight>

(The <code>mp</code> variable stands for '''M'''odule '''F'''ormatnum; you can choose something more descriptive if you prefer.)

Most functions in the module have a version for Lua and a version for #invoke. It is possible to use the #invoke functions from other Lua modules, but using the Lua functions has the advantage that you do not need to access a Lua [[mw:Extension:Scribunto/Lua reference manual#Frame object|frame object]]. Lua functions are preceded by <code>_</code>, whereas #invoke functions are not.

== main ==

&#123;{#invoke:Formatnum|main|''x''|''lang=''|''prec=''|''sep=''}}

<syntaxhighlight lang="lua">
mf.formatNum(x, lang, prec, sep)
</syntaxhighlight>

== wordify ==

&#123;{#invoke:Formatnum|wordify|''x''|''numsys=''|''prec=''|''lk=''}}

<syntaxhighlight lang="lua">
mf._wordify(x, numsys, prec, lk)
</syntaxhighlight>

Wordify x.

* numsys can be 'usa' (the default) or 'ind'
* prec is the digits of precision to output
* if lk is true ("on" for #invoke), the units will be linked

==See also==
{{Math templates}}

<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |
<!-- Categories below this line, please; interwikis at Wikidata -->

}}</includeonly>

Revision as of 18:12, 19 February 2021

This module provides a number formatting functions. These functions can be used from #invoke or from other Lua modules.

This module is used by Module:Complex date and {{FXConvert}}

Use from other Lua modules

To use the module from normal wiki pages, no special preparation is needed. If you are using the module from another Lua module, first you need to load it, like this:

local mf = require('Module:Formatnum')

(The mp variable stands for Module Formatnum; you can choose something more descriptive if you prefer.)

Most functions in the module have a version for Lua and a version for #invoke. It is possible to use the #invoke functions from other Lua modules, but using the Lua functions has the advantage that you do not need to access a Lua frame object. Lua functions are preceded by _, whereas #invoke functions are not.

main

{{#invoke:Formatnum|main|x|lang=|prec=|sep=}}
mf.formatNum(x, lang, prec, sep)

wordify

{{#invoke:Formatnum|wordify|x|numsys=|prec=|lk=}}
mf._wordify(x, numsys, prec, lk)

Wordify x.

  • numsys can be 'usa' (the default) or 'ind'
  • prec is the digits of precision to output
  • if lk is true ("on" for #invoke), the units will be linked

See also