mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Math: As unit conversion algorithm fails with high precision, make significant digits matter.
This commit is contained in:
parent
018ee3456d
commit
ea63da3e7d
@ -308,9 +308,19 @@ class Math(callbacks.Plugin):
|
|||||||
Converts from <unit> to <other unit>. If number isn't given, it
|
Converts from <unit> to <other unit>. If number isn't given, it
|
||||||
defaults to 1. For unit information, see 'units' command.
|
defaults to 1. For unit information, see 'units' command.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
digits = len(str(number).split('.')[1])
|
||||||
|
except IndexError:
|
||||||
|
digits = 0
|
||||||
try:
|
try:
|
||||||
newNum = convertcore.convert(number, unit1, unit2)
|
newNum = convertcore.convert(number, unit1, unit2)
|
||||||
newNum = self._floatToString(newNum)
|
newNum = self._floatToString(newNum)
|
||||||
|
if isinstance(newNum, float):
|
||||||
|
# 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)
|
||||||
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