Content deleted Content added
Fixing precision issues with lengths that are multiples of 10 |
Reorder statements |
||
Line 42:
if not km then -- This signifies that a length in kilometers was not passed.
local n = tonumber(mi) -- The first step is to convert the miles (passed as a string from the template) into a number.
local ten_mult = (n % 10 == 0) -- Rounding is handled differently if the input distance is a multiple of 10.▼
if n then -- If the passed mile value is an empty string, n will equal nil, which would make this statement false. Otherwise, the length in kilometers is computed and stored.
▲ local ten_mult = (n % 10 == 0) -- Rounding is handled differently if the input distance is a multiple of 10.
local prec = precision(mi) -- Retrieve the precision of the passed mile value (as a string).
if ten_mult and prec < 0 then -- If the distance is a multiple of 10 and a whole number...
Line 58:
if not mi then -- The same as above, but this time converting kilometers to mile if necessary.
local n = tonumber(km) -- Kilometers as a number
local ten_mult = (n % 10 == 0) -- Rounding is handled differently if the input distance is a multiple of 10.▼
if n then -- If a kilometer value was passed:
▲ local ten_mult = (n % 10 == 0) -- Rounding is handled differently if the input distance is a multiple of 10.
local prec = precision(km) -- Precision of the passed length
if ten_mult and prec < 0 then -- If the distance is a multiple of 10 and a whole number...
|