Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Math: Fix rounding.

  • Loading branch information...
commit bbd9d1636a97ebd697369663d1669d461d8c215f 1 parent c1f19b3
@ProgVal authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 plugins/Math/plugin.py
View
9 plugins/Math/plugin.py
@@ -314,13 +314,18 @@ def convert(self, irc, msg, args, number, unit1, unit2):
digits = 0
try:
newNum = convertcore.convert(number, unit1, unit2)
- newNum = self._floatToString(newNum)
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
# that, but common people usually do not give extra zeros...
# (for example, with '32 C to F', an extra digit would be
# expected).
- newNum = round(newNum, digits+1)
+ newNum = round(newNum, digits + 1 + zeros)
+ newNum = self._floatToString(newNum)
irc.reply(str(newNum))
except convertcore.UnitDataError, ude:
irc.error(str(ude))
Please sign in to comment.
Something went wrong with that request. Please try again.