Jump to content

Module:Math: Difference between revisions

No change in size ,  11 years ago
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 p._order(tonumber(frame.args[1] or frame.args.x or 0))
     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 = p._precision( value );
     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 = p._order( value );
     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 );
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.