Přeskočit na obsah

Modul:Wikidata/Formatters/approx

Tuto stránku mohou editovat jen zavedení uživatelé a správci.
Z Wikipedie, otevřené encyklopedie
(rozdíl) ← Starší revize | zobrazit aktuální verzi (rozdíl) | Novější revize → (rozdíl)

local p = require 'Modul:Wikidata/Formatters/quantity'

local function roundToHundreds(value)
	local remainder = value % 100
	if remainder < 50 then
		return math.floor(value / 100) * 100
	else
		return math.ceil(value / 100) * 100
	end
end

function p.getText(value, options)
	if value > 1000 and value < 10000 then
		return mw.ustring.format('přibližně %s', p.formatRawValue(roundToHundreds(value)))
	elseif value > 10000 and value < 1000000 then
		return mw.ustring.format('přes %s tisíc', p.formatRawValue(math.floor(value / 1000)))
	else
		return p.formatRawValue(value, options)
	end
end

function p.formatValue(value, options)
	local raw = p.getRawValue(value, options)
	return p.getText(raw, options)
end

return p