Jump to content

Module:ConvertMPHKMHTCStats

From Shark's Hypothetical Weather
Revision as of 23:28, 30 May 2025 by Sharkius (talk | contribs) (Created page with "local p = {} function round(num, digits) digits = digits or 0 local mult = 10 ^ digits return math.floor(num * mult + 0.5) / mult end function p.main(frame) local args = frame.args local mph = tonumber(args[1]) local sigfig = tonumber(args["sigfig"]) or 4 if not mph then return "" end local kmh = mph * 1.609344 -- Round to nearest integer local rounded_mph = round(mph) local rounded_kmh = round(kmh) return string.format("%d (%d)", rounded_mph, rounded_k...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:ConvertMPHKMHTCStats/doc

local p = {}

function round(num, digits)
	digits = digits or 0
	local mult = 10 ^ digits
	return math.floor(num * mult + 0.5) / mult
end

function p.main(frame)
	local args = frame.args
	local mph = tonumber(args[1])
	local sigfig = tonumber(args["sigfig"]) or 4

	if not mph then return "" end

	local kmh = mph * 1.609344

	-- Round to nearest integer
	local rounded_mph = round(mph)
	local rounded_kmh = round(kmh)

	return string.format("%d (%d)", rounded_mph, rounded_kmh)
end

return p