mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 14:59:34 +01:00
Yay, now we can convert negative numbers between bases
This commit is contained in:
parent
915d4674e3
commit
8623e98939
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user