| Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
| Modul | Deutsch | English
|
Modul: | Dokumentation | |||
FormatNum – Module containing methods for rounding and formatting of numbers. Various variants are offered.
Format a number according to requested specification. Any number using a dot as decimal separator, no separation for thousands, and no exponential represention, consisting of ASCII characters only. See #Formatting options.
Parameter
at, ch, ch_currency, comma, de, dewiki, de_currency, en, iso31_0, iso31_0_point and pc.dewikiResult
A heading Unicode minus sign U+2212 = 872210 will be replaced by ASCII hyphen U+002D; or vice versa.
Parameter
0 = →ASCII (boolean)Result
1.Padding to the left or right with whitespace which will not be transferred by copy&paste. The number will be filled left or right until decimal separator in a way that all figures show the decimal separator below each other, if extension has been chosen appropriately.
Parameter
Result
Turn roman number into numerical integer.
Parameter
%.$ – request a period following the roman number as common in some languages, or %.?$.Result
Round a number. Results in a string with the requested number of significant digits. Any number that can be parsed by Lua method tonumber() may be used.
Parameter
-1), full hundreds (for -2) etc.0 – Round according to IEEE 754 (round half to even).1 – Commercial rounding, inkluding elimination of -0 results.0format subsequently.dewiki).padding and format subsequently.format=. The decimal separator results from formatting method.Result
format or immediately applied by format= or padding=.-0, the result is always an integer number.Version ID: 2020-08-06
1 – required version, or keyword wikidataReturns:
2020-08-06) when wikidata| Format | Decimal separator |
Thousands separator (Tsep) |
Tsep from length |
Tsep just integer part |
Examples | |
|---|---|---|---|---|---|---|
| de | , | Thin whitespace | 5* | no | 123,456 1 234,567 12 345,678 1 234,567 8 12 345,567 8 |
-123,456 -1 234,567 -12 345,678 -1 234,567 8 -12 345,567 8 |
| de_currency dewiki |
, | . | 5 | yes | 123,456 1.234,567 12.345,678 1.234,5678 12.345,5678 |
-123,456 -1.234,567 -12.345,678 -1.234,5678 -12.345,5678 |
| ch | , | ' | 5 | yes | 123,456 1234,567 12'345,678 1234,5678 12'345,5678 |
-123,456 -1234,567 -12'345,678 -1234,5678 -12'345,5678 |
| ch_currency | . | ' | 5 | yes | 123.456 1234.567 12'345.678 1234.5678 12'345.5678 |
-123.456 -1234.567 -12'345.678 -1234.5678 -12'345.5678 |
| en | . | , | 4 | yes | 123.456 1,234.567 12,345.678 1,234.5678 12,345.5678 |
-123.456 -1,234.567 -12,345.678 -1,234.5678 -12,345.5678 |
| iso31_0 at |
, | Thin whitespace | 4 | no | 123,456 1 234,567 12 345,678 1 234,567 8 12 345,567 8 |
-123,456 -1 234,567 -12 345,678 -1 234,567 8 -12 345,567 8 |
| iso31_0_point | . | Thin whitespace | 4 | no | 123.456 1 234.567 12 345.678 1 234.567 8 12 345.567 8 |
-123.456 -1 234.567 -12 345.678 -1 234.567 8 -12 345.567 8 |
| pc | . | 123.456 1234.567 12345.678 1234.5678 12345.5678 |
-123.456 -1234.567 -12345.678 -1234.5678 -12345.5678 | |||
| comma | , | 123,456 1234,567 12345,678 1234,5678 12345,5678 |
-123,456 -1234,567 -12345,678 -1234,5678 -12345,5678 | |||
* Since the thousands separator is applied to the part after decimal separator, a length of 5 is relevant only if there is a part after decimal separator with maximal 3 digits. On 4 or more digits after decimal separator the integer part will be divided also on 4 digits.
There are tests available to illustrate this in practice.
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
wikidataThis is a general library; use it anywhere. Dedicated to be wrapped into relevant templates.
None.
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.