Math: Fix crash in @convert on small/large single-digit numbers

str() converts them to the exponent notation, which makes split('.')[1]
crash, since there is no decimal part in the exponent notation when there
is a single significant digit.
This commit is contained in:
Valentin Lorentz 2021-11-28 17:59:59 +01:00
parent 2d5c80736d
commit c0d033ff84
2 changed files with 2 additions and 1 deletions

View File

@ -246,7 +246,7 @@ class Math(callbacks.Plugin):
newNum = convertcore.convert(number, unit1, unit2)
if isinstance(newNum, float):
zeros = 0
for char in str(newNum).split('.')[1]:
for char in "{:f}".format(newNum).split('.')[1]:
if char != '0':
break
zeros += 1

View File

@ -166,6 +166,7 @@ class MathTestCase(PluginTestCase):
self.assertResponse('convert 1 m to cm', '100')
self.assertResponse('convert m to cm', '100')
self.assertResponse('convert 3 metres to km', '0.003')
self.assertResponse('convert 1 cm to km', '1e-05')
self.assertResponse('convert 32 F to C', '0')
self.assertResponse('convert 32 C to F', '89.6')
self.assertResponse('convert [calc 2*pi] rad to degree', '360')