Modul:Wikidata/Formatters/round
Vzhled
Dokumentaci tohoto modulu lze vytvořit na stránce Modul:Wikidata/Formatters/round/Dokumentace
require 'Modul:No globals'
local p = {}
local parent = require 'Modul:Wikidata/Formatters/quantity'
p.getRawValue = parent.getRawValue
local function roundToOneDecimal(value)
return tonumber(mw.ustring.format('%.1f', value))
end
function p.formatNumber(value, options)
local formatNumber = parent.formatNumber
local absolute = math.abs(value)
if 10^6 < absolute and absolute < 10^9 then
return mw.ustring.format('%s mil.', formatNumber(roundToOneDecimal(value / 10^6), {}))
elseif 10^9 < absolute and absolute < 10^12 then
return mw.ustring.format('%s mld.', formatNumber(roundToOneDecimal(value / 10^9), {}))
elseif 10^12 < absolute and absolute < 10^15 then
return mw.ustring.format('%s bil.', formatNumber(roundToOneDecimal(value / 10^12), {}))
else
return formatNumber(value, options)
end
end
p.formatRawValue = p.formatNumber
function p.formatValue(value, options)
parent.setFormatNumber(p.formatNumber)
return parent._formatValue(value, options)
end
return p