View source for Module:Utils/number
From Space Station 14 Wiki
You do not have permission to edit this page, for the following reason:
You can view and copy the source of this page.
local p = {}
-- Rounds number `num` to `digits` numbers after comma.
-- @returns {number}
function p.round_to_digit(num, digits)
local str_res = string.format("%." .. digits .. "f", num)
:gsub("%.?0+$", "") -- strip trailing zeros (including the dot if theres all zeros after)
return tonumber(str_res)
end
-- Rounds number `num` to `digits` numbers after comma,
-- adding "≈" if rounding occured.
-- @returns {string}
function p.round_to_digit_formatted(num, digits)
local rounded = p.round_to_digit(num, digits)
if num == rounded then
return tostring(rounded)
else
return "≈" .. rounded
end
end
000
1:0
Templates used on this page:
Return to Module:Utils/number.