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.
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
-- Formats a probability number, ranging from 0 to 1,
-- to a percentage with specified number of digits after comma.
-- If rounding occurs, also adds "≈".
-- @param prob Probability, from 0 to 1.
-- @param digits Digits after comma. Any more get rounded.
function p.format_probability(prob, digits)
local percentage = prob * 100
local percentage_display
if digits == nil then
percentage_display = percentage .. "%"
else
000
1:0
Templates used on this page:
Return to Module:Utils/number.