Zum Inhalt springen

Wikipedia:Lua/Modul/FormatNum/en

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 19. Juni 2019 um 20:51 Uhr durch PerfektesChaos (Diskussion | Beiträge) (Setup). Sie kann sich erheblich von der aktuellen Version unterscheiden.
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
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 keyword wikidata

Returns:

  • (empty), if minimal version condition not matched
  • local version otherwise, or registered on Wikidata (2020-08-06) when wikidata

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.