mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-26 04:32:51 +01:00
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:
parent
2d5c80736d
commit
c0d033ff84
@ -246,7 +246,7 @@ class Math(callbacks.Plugin):
|
|||||||
newNum = convertcore.convert(number, unit1, unit2)
|
newNum = convertcore.convert(number, unit1, unit2)
|
||||||
if isinstance(newNum, float):
|
if isinstance(newNum, float):
|
||||||
zeros = 0
|
zeros = 0
|
||||||
for char in str(newNum).split('.')[1]:
|
for char in "{:f}".format(newNum).split('.')[1]:
|
||||||
if char != '0':
|
if char != '0':
|
||||||
break
|
break
|
||||||
zeros += 1
|
zeros += 1
|
||||||
|
@ -166,6 +166,7 @@ class MathTestCase(PluginTestCase):
|
|||||||
self.assertResponse('convert 1 m to cm', '100')
|
self.assertResponse('convert 1 m to cm', '100')
|
||||||
self.assertResponse('convert m to cm', '100')
|
self.assertResponse('convert m to cm', '100')
|
||||||
self.assertResponse('convert 3 metres to km', '0.003')
|
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 F to C', '0')
|
||||||
self.assertResponse('convert 32 C to F', '89.6')
|
self.assertResponse('convert 32 C to F', '89.6')
|
||||||
self.assertResponse('convert [calc 2*pi] rad to degree', '360')
|
self.assertResponse('convert [calc 2*pi] rad to degree', '360')
|
||||||
|
Loading…
Reference in New Issue
Block a user