Module:Math: Difference between revisions
m
fix
m>Dragons flight (Add support for rounding to specified precsion) |
m>Dragons flight m (fix) |
||
Line 17: | Line 17: | ||
-- Determine order of magnitude | -- Determine order of magnitude | ||
function z.order(frame) | function z.order(frame) | ||
return | return z._order(tonumber(frame.args[1] or frame.args.x or 0)) | ||
end | end | ||
function z._order(x) | function z._order(x) | ||
Line 111: | Line 111: | ||
local value = tonumber( frame.args[1] or 0 ); | local value = tonumber( frame.args[1] or 0 ); | ||
local precision = tonumber( frame.args[2] or 0 ); | local precision = tonumber( frame.args[2] or 0 ); | ||
local current_precision = | local current_precision = z._precision( value ); | ||
-- If rounding off, truncate extra digits | -- If rounding off, truncate extra digits | ||
Line 123: | Line 123: | ||
-- Handle cases requiring scientific notation | -- Handle cases requiring scientific notation | ||
order = | order = z._order( value ); | ||
if string.find( formatted_num, 'E', 1, true ) ~= nil or math.abs(order) >= 9 then | if string.find( formatted_num, 'E', 1, true ) ~= nil or math.abs(order) >= 9 then | ||
value = value * math.pow( 10, -order ); | value = value * math.pow( 10, -order ); |