Module:Gapnum/doc: Difference between revisions
Appearance
Content deleted Content added
The Mol Man (talk | contribs) ←Created page with 'Implements Template:Gapnum' |
The Mol Man (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
Implements [[Template:Gapnum]] |
Implements [[Template:Gapnum]] |
||
== Use in other modules == |
|||
The <code>gaps</code> function can be useful for [[MOS:DIGITS|formatting]] in other modules that work with displaying large numbers. |
|||
<source lang="lua"> |
|||
local gaps = require('Module:Gapnum').gaps |
|||
</source> |
|||
Using the <code>gaps</code> function, the first argument is the number to format. The second argument can be a table with keys that tell the module how to format. The table keys that can be used are: |
|||
* <code>gap</code> - a number with CSS units (px, em, en, etc) that define the size of the gap between numbers. If blank, the module will use <code>0.25em</code>. |
|||
* <code>prec</code> - a number that determines the precision of the decimal part of the number. If the precision is less than the number of digits, extra digits will be removed without rounding; if it is more, zeroes will be added to the end to create the desired precision. If blank, the module will use <code>-1</code>, which means the precision will be the same as the number given; no digits added or removed. |
|||
<source lang="lua"> |
|||
local gaps = require('Module:Gapnum').gaps |
|||
function example() |
|||
local n = 123456.78900011 |
|||
-- Example for just simple formatting of a number |
|||
-- n_gaps will use the default, .25em gaps and no change in precision |
|||
-- The result will have its gaps created with inline css |
|||
-- But the result would look like: |
|||
-- 123 456.789 000 11 |
|||
local n_gaps = gaps(n) |
|||
-- Defining a size of gaps |
|||
local n_big_gaps = gaps(n, {gap='1em'}) |
|||
local n_small_gaps = gaps(n, {gap='1px'}) |
|||
-- Different precision |
|||
-- n_prec_5 will use the number 123456.78900 |
|||
-- The result would look like: |
|||
-- 123 456.789 00 |
|||
local n_prec_5 = gaps(n, {prec=5}) |
|||
-- n_prec_10 will use the number 123456.7890001100 |
|||
-- The result would look like: |
|||
-- 123 456.789 000 1100 |
|||
local n_prec_10 = gaps(n, {prec=10}) |
|||
-- Both different gaps and precision can be used: |
|||
local n_big_5 = gaps(n, {gap='1em', prec=5}) |
|||
local n_small_10 = gaps(n, {gap='1px', prec=10}) |
|||
end |
|||
</source> |
Revision as of 16:02, 7 January 2015
Implements Template:Gapnum
Use in other modules
The gaps
function can be useful for formatting in other modules that work with displaying large numbers.
local gaps = require('Module:Gapnum').gaps
Using the gaps
function, the first argument is the number to format. The second argument can be a table with keys that tell the module how to format. The table keys that can be used are:
gap
- a number with CSS units (px, em, en, etc) that define the size of the gap between numbers. If blank, the module will use0.25em
.prec
- a number that determines the precision of the decimal part of the number. If the precision is less than the number of digits, extra digits will be removed without rounding; if it is more, zeroes will be added to the end to create the desired precision. If blank, the module will use-1
, which means the precision will be the same as the number given; no digits added or removed.
local gaps = require('Module:Gapnum').gaps
function example()
local n = 123456.78900011
-- Example for just simple formatting of a number
-- n_gaps will use the default, .25em gaps and no change in precision
-- The result will have its gaps created with inline css
-- But the result would look like:
-- 123 456.789 000 11
local n_gaps = gaps(n)
-- Defining a size of gaps
local n_big_gaps = gaps(n, {gap='1em'})
local n_small_gaps = gaps(n, {gap='1px'})
-- Different precision
-- n_prec_5 will use the number 123456.78900
-- The result would look like:
-- 123 456.789 00
local n_prec_5 = gaps(n, {prec=5})
-- n_prec_10 will use the number 123456.7890001100
-- The result would look like:
-- 123 456.789 000 1100
local n_prec_10 = gaps(n, {prec=10})
-- Both different gaps and precision can be used:
local n_big_5 = gaps(n, {gap='1em', prec=5})
local n_small_10 = gaps(n, {gap='1px', prec=10})
end