„Wikipedia:Lua/Modul/FormatNum/en“ – Versionsunterschied
Erscheinungsbild
Inhalt gelöscht Inhalt hinzugefügt
Setup |
(kein Unterschied)
|
Version vom 19. Juni 2019, 20:51 Uhr
Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
Modul | Deutsch | English
|
Modul: | Dokumentation |
FormatNum
– Module containing methods for rounding and formatting of numbers. Various variants are offered.
Functions for templates
failsafe
Version ID: 2020-08-06
- optional parameter
1
– required version, or keywordwikidata
Returns:
- (empty), if minimal version condition not matched
- local version otherwise, or registered on Wikidata (
2020-08-06
) whenwikidata
Examples and test page
There are tests available to illustrate this in practice.
Use in another Lua module
All of the above functions can be called from other Lua modules, if not Lua library function anyway. Use require()
; the below code checks for errors loading it:
local lucky, FormatNum = pcall( require, "Module:FormatNum" )
if type( FormatNum ) == "table" then
FormatNum = FormatNum.FormatNum()
else
-- In the event of errors, FormatNum is an error message.
return "<span class=\"error\">" .. FormatNum .. "</span>"
end
- FormatNum.format(source, spec, meet)
-
- source: string
- spec: optional string
- meet: optional number (extension for internal padding)
- FormatNum.minus(source, larger)
-
- source: string
- larger: optional boolean (conversion into Unicode)
- FormatNum.padding(source, meet, stop)
-
- source: string
- meet: number
- stop: string
- FormatNum.roman2number(source, suffix)
-
- source: string
- suffix: optional string
- FormatNum.round(source, precision, method)
-
- source: string
- precision: number
- method: optional number
- FormatNum.format(assert)
-
- assert: optional string
- FormatNum()
- Yields table with access to functions (see above).
Internals
Usage
This is a general library; use it anywhere. Dedicated to be wrapped into relevant templates.
Dependencies
None.