mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Math: Fix rounding.
This commit is contained in:
parent
c1f19b3353
commit
bbd9d1636a
@ -314,13 +314,18 @@ class Math(callbacks.Plugin):
|
|||||||
digits = 0
|
digits = 0
|
||||||
try:
|
try:
|
||||||
newNum = convertcore.convert(number, unit1, unit2)
|
newNum = convertcore.convert(number, unit1, unit2)
|
||||||
newNum = self._floatToString(newNum)
|
|
||||||
if isinstance(newNum, float):
|
if isinstance(newNum, float):
|
||||||
|
zeros = 0
|
||||||
|
for char in str(newNum).split('.')[1]:
|
||||||
|
if char != '0':
|
||||||
|
break
|
||||||
|
zeros += 1
|
||||||
# Let's add one signifiant digit. Physicists would not like
|
# Let's add one signifiant digit. Physicists would not like
|
||||||
# that, but common people usually do not give extra zeros...
|
# that, but common people usually do not give extra zeros...
|
||||||
# (for example, with '32 C to F', an extra digit would be
|
# (for example, with '32 C to F', an extra digit would be
|
||||||
# expected).
|
# expected).
|
||||||
newNum = round(newNum, digits+1)
|
newNum = round(newNum, digits + 1 + zeros)
|
||||||
|
newNum = self._floatToString(newNum)
|
||||||
irc.reply(str(newNum))
|
irc.reply(str(newNum))
|
||||||
except convertcore.UnitDataError, ude:
|
except convertcore.UnitDataError, ude:
|
||||||
irc.error(str(ude))
|
irc.error(str(ude))
|
||||||
|
Loading…
Reference in New Issue
Block a user