X-Git-Url: http://git.maemo.org/git/?p=gonvert;a=blobdiff_plain;f=src%2Fconverters.py;h=d53c76816a2a58a07f86dbe26b30e74a9fa15d2e;hp=f85120e7784c0177159622af7d0bb83bec6a2392;hb=1e2010632954ab734663bbc674b621b33c1d4374;hpb=a052e0851cc23098d6f1caf0492fe9dd889af877 diff --git a/src/converters.py b/src/converters.py index f85120e..d53c768 100644 --- a/src/converters.py +++ b/src/converters.py @@ -226,6 +226,9 @@ class base_converter(object): """ Convert from any base to base 10 (decimal) """ + # Protection against fractional values + value = value.split(".", 1)[0] + result = 0L #will contain the long base-10 (decimal) number to be returned position = len(value) #length of the string that is to be converted for x in value: @@ -237,7 +240,7 @@ class base_converter(object): """ Convert from decimal to any base """ - return makeBase(value, base) + return makeBase(int(value), base) class roman_numeral(object): @@ -255,7 +258,7 @@ class roman_numeral(object): """ Convert from decimal to roman numeral """ - return toroman(value) + return toroman(int(value)) @@ -265,10 +268,12 @@ class function(object): #value is assumed to be a string #convert from a defined function to base def to_base(self, value, (to_base, from_base)): + y = 0 # "undefined" y was driving me nuts exec "y="+to_base[:to_base.find('x')]+str(value)+to_base[to_base.find('x')+1:] return y def from_base(self, value, (to_base, from_base)): + y = 0 # "undefined" y was driving me nuts exec "y="+from_base[:from_base.find('x')]+str(value)+from_base[from_base.find('x')+1:] return y