Content deleted Content added
Sync with sandbox: Sortkey as anchor; unlinking possible; use Module:Arguments; other fixes |
Moving precision checks inside if blocks to avoid nil-related errors |
||
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 prec = precision(mi) -- Retrieve the precision of the passed mile value (as a string).▼
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 prec = precision(mi) -- Retrieve the precision of the passed mile value (as a string).
length.km = round(n * 1.609344, prec) -- Compute and round the length in kilometers, and store it in the length table.
else -- No mile value was passed
Line 53:
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 prec = precision(km) -- Precision of the passed length▼
if n then -- If a kilometer value was passed:
▲ local prec = precision(km) -- Precision of the passed length
length.mi = round(n / 1.609344, prec) -- Compute and store the conversion into miles.
else -- If not:
|