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