Yay, now we can convert negative numbers between bases

This commit is contained in:
James Vega 2004-02-09 03:08:33 +00:00
parent 915d4674e3
commit 8623e98939

View File

@ -90,6 +90,10 @@ class Math(callbacks.Privmsg):
"""
Convert a decimal number to another base; returns a string.
"""
negative = False
if number < 0:
negative = True
number = -number
valStr = ''
if number == 0:
return '0'
@ -101,7 +105,10 @@ class Math(callbacks.Privmsg):
digit = str(digit)
valStr = digit + valStr
number = int(math.floor(number / base))
return valStr
if negative:
return '-%s' % valStr
else:
return valStr
def _convertBaseToBase(self, number, toBase, fromBase):
"""