Module:Gapnum/doc
This is the documentation page for Modul:Gapnum
This module is used by {{val}}.
Anggén ring modul tiosan
[edit source]gaps
[edit source]Fungsi gaps
keangén antuk ring modul tiosan sané mefungsi nampilang jumlah akéh.
local gaps = require('Module:Gapnum').gaps
Anggén fungsi gaps
, pesogsag kapertama punika angka kaformat. Pesogsag kaping kalih bisa marupa tabel sareng kunci sané nikayang cara ngeformat modul. Kunci tabel sané prasida keanggén punika:
gap
- angka nganggén satuan CSS (px, em, en, mst) sané nentuang ukuran jarak riantara angka. Rikala puyung, modul pacang keanggén0.25em
.prec
- angka sané nentuang katepatan wagian desimal saking angka punika. Rikala presisi kirang saking jumlah digit, digit katambah pacang kehapus tanpa pembunteran; rikala luwih, nol pacang katambah ka untat antuk nagraynin presisi sané karereh. Rikala puyung, modul pacang nganggén-1
, sané mearti presisi pacang pateh sareng angka sané kaisi; nénten wénten digit sané katambahang utawi kahapus.
Cingakin penyawis punika situnggil tabel. Puniki mearti luwih akeh gaya utawi teks prasida katambahang ring bungkus tag rentang, menawi bisa malih mearti punika tostring()
karereh rikala keanggén ring modul tiosan.
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)
-- Different gap size
-- These will format n into the same groups as above
-- But the spaces between the groups will be larger and smaller, respectively
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
groups
[edit source]Fungsi groups
prasida keanggén ring modul tiosan antuk melasang nomor dados grup gaps
, menawi format ipun nénten string
, fungsi pacang ngwalikang tabel sané élemén-élemén punika kelompok-kelompok sané kapisah.
local groups = require('Module:Gapnum').groups
function example()
-- This will return one table:
-- {123,456}
local n1 = groups(123456)
-- This will return two tables, each assigned to a different variable:
-- n2a will be:
-- {1,234}
-- n2b will be:
-- {567,89}
local n2a,n2b = groups(1234.56789)
-- This will return two tables:
-- An integer part is always returned, even if it is 0
-- n3a will be:
-- {0}
-- n3b will be:
-- {123,4567}
local n3a,n3b = groups(0.1234567)
-- Just like the other functions, a precision can be defined
-- precision is simply the second parameter
-- n4a will be:
-- {123}
-- n4b will be:
-- {456,700,00}
local n4a,n4b = groups(123.4567,8)
end