Module:Utils: Difference between revisions

Plumtree (talk | contribs)
m Small optimisation
Plumtree (talk | contribs)
m round() behaviour restored
Line 48: Line 48:
prec = p.eval_num_arg(prec, 6)
prec = p.eval_num_arg(prec, 6)
local s = string.format(string.format("%%.%df", prec), x)
local s = string.format(string.format("%%.%df", prec), x)
-- remove non-significant digits
local sep_pos = s:find('%.')
if prec >= sep_pos then
s = s:sub(1, prec + 1)
else
s = s:sub(1, prec)
while #s < sep_pos - 1 do
s = s .. '0'
end
end
-- remove unnecessary zeros
-- remove unnecessary zeros
if s:find('%.') then
if s:find('%.') then