Jump to content
Main menu
Main menu
move to sidebar
hide
Nabegashon
Página prinsipal
Portal di komunidat
Kambionan resien
Kualke página
Yudansa
Buska
Buska
Appearance
Duna
Krea kuenta
Registrá
Hèrmèntnan personal
Duna
Krea kuenta
Registrá
Pages for logged out editors
learn more
Kontribushonnan
Diskushon
Pa redaktá
Module:ConvertNumeric
Add languages
Module
Diskushon
English
Lesa
Editá fuente
Bista di e historia
Hèrmènt
Tools
move to sidebar
hide
Actions
Lesa
Editá fuente
Bista di e historia
General
Kiko ta link aki
E kambio relacionnan ku e
Subi fail
Informashon di e página
Get shortened URL
Download QR code
Appearance
move to sidebar
hide
Bo no a
outentiká bo mes
. Bo por kambia página libremente, pero tene kuenta ku lo nota bo
IP adrès
den e
historia
di kambionan hasí na e página aki.
Anti-spam check. Do
not
fill this in!
-- Module for converting between different representations of numbers -- Adapted to handle variants (e.g., default, 'c', etc.) require('strict') -- Default variant and additional variant 'c' local variants = { default = { ones_position = { [0] = 'cero', [1] = 'un', [2] = 'dos', [3] = 'tres', [4] = 'cuatro', [5] = 'cinco', [6] = 'seis', [7] = 'siete', [8] = 'ocho', [9] = 'nueve', [10] = 'diez', [11] = 'once', [12] = 'doce', [13] = 'trece', [14] = 'catorce', [15] = 'quince', [16] = 'dieciséis', [17] = 'diecisiete', [18] = 'dieciocho', [19] = 'diecinueve' }, tens_position = { [2] = 'veinte', [3] = 'treinta', [4] = 'cuarenta', [5] = 'cincuenta', [6] = 'sesenta', [7] = 'setenta', [8] = 'ochenta', [9] = 'noventa' }, groups = { [1] = 'mil', [2] = 'millón', [3] = 'billón', [4] = 'trillón' -- Add more as needed } }, c = { ones_position = { [0] = 'sero', [1] = 'uno', [2] = 'do', [3] = 'tre', [4] = 'quatro', [5] = 'cinco', [6] = 'sei', [7] = 'sete', [8] = 'ocho', [9] = 'nueve', [10] = 'die', [11] = 'onceuno', [12] = 'oncesdo', [13] = 'onctre', [14] = 'oncequatro', [15] = 'oncecinco', [16] = 'oncesseis', [17] = 'oncsiete', [18] = 'oncocho', [19] = 'oncnueve' }, tens_position = { [2] = 'binti', [3] = 'trinta', [4] = 'quarenta', [5] = 'cincuenta', [6] = 'sesenta', [7] = 'setenta', [8] = 'ochenta', [9] = 'nobenta' }, groups = { [1] = 'mil', [2] = 'miom', [3] = 'biyon' -- Add more as needed } } } local function get_variant_table(variant) return variants[variant] or variants.default end local function numeral_to_english_less_100(num, variant, ordinal, plural, zero) local tables = get_variant_table(variant) local terminal_ones = ordinal and ones_position_ord or (plural and ones_position_plural or tables.ones_position) local terminal_tens = ordinal and tens_position_ord or (plural and tens_position_plural or tables.tens_position) if num == 0 and zero then return zero elseif num < 20 then return terminal_ones[num] elseif num % 10 == 0 then return terminal_tens[num / 10] else return terminal_tens[math.floor(num / 10)] .. '-' .. terminal_ones[num % 10] end end local function numeral_to_english_less_1000(num, variant, use_and, ordinal, plural, zero) num = tonumber(num) local tables = get_variant_table(variant) if num < 100 then return numeral_to_english_less_100(num, variant, ordinal, plural, zero) elseif num % 100 == 0 then return tables.ones_position[math.floor(num / 100)] .. ' hundred' .. (ordinal and 'th' or (plural and 's' or '')) else return tables.ones_position[math.floor(num / 100)] .. ' hundred ' .. (use_and and 'and ' or '') .. numeral_to_english_less_100(num % 100, variant, ordinal, plural, zero) end end local function _numeral_to_english(num, variant, numerator, denominator, capitalize, use_and, hyphenate, ordinal, plural, links, negative_word, round, zero, use_one) local tables = get_variant_table(variant) num = scientific_notation_to_decimal(num) if round and round ~= '' then num = round_for_english(num, round) end local MINUS = '−' if num:sub(1, #MINUS) == MINUS then num = '-' .. num:sub(#MINUS + 1) elseif num:sub(1, 1) == '+' then num = num:sub(2) end local negative = num:find("^%-") local decimal_places, subs = num:gsub("^%-?%d*%.(%d+)$", "%1") if subs == 0 then decimal_places = nil end num, subs = num:gsub("^%-?(%d*)%.?%d*$", "%1") if num == '' and decimal_places then num = '0' end if subs == 0 or num == '' then error("Invalid decimal numeral") end local s = '' while #num > 3 do if s ~= '' then s = s .. ' ' end local group_num = math.floor((#num - 1) / 3) local group = tables.groups[group_num] local group_digits = #num - group_num * 3 s = s .. numeral_to_english_less_1000(num:sub(1, group_digits), variant, false, false, false, nil) .. ' ' .. group num = num:sub(group_digits + 1) end s = s .. numeral_to_english_less_1000(num, variant, false, false, false, nil) if negative then s = 'minus ' .. s end if capitalize then s = s:gsub("^%l", string.upper) end if hyphenate then s = s:gsub("%s", "-") end return s end -- Example usage: print(_numeral_to_english("1234", "default", nil, nil, false, true, false, false, false, nil, nil, nil, nil, nil)) print(_numeral_to_english("1234", "c", nil, nil, false, true, false, false, false, nil, nil, nil, nil, nil))
Resúmen:
Si bo warda e kambionan, bo ta bai di akuerdo ku
Terms of Use
, i bo ta aseptá, sin posibilidat di kambia esaki, pa publiká bo kontribushon segun
CC BY-SA 4.0 License
i
GFDL
. Bo ta bai di akuerdo ku un hyperlink òf URL ta sufisiente atribushon segun e lisensia Creative Commons.
Kanselá
Yudansa ku editamentu
(ta habri den un bentana nobo)
Preview page with this template
Wikidata entities used in this page
Module:ConvertNumeric
: Sitelink, Description: en
Malchi uzá na e página akí:
Module:ConvertNumeric/doc
(
editá
)
Buska
Buska
Pa redaktá
Module:ConvertNumeric
Add languages
Añadí un tópiko