Converting exponential numbers to strings.
Steve
steveb at nebcoinc.com
Mon Nov 5 16:50:23 EST 2001
Hi,
I'm new to python and I'm trying to write a routine to determine
whether or not an object is numeric like so:
def isnumeric(s,allow_dec=0,allow_neg=0):
decimal_found = 0
negative_found = 0
if s == "":
return 0
for x in str(s):
if x not in string.digits:
if x == "." and allow_dec:
if decimal_found:
return 0
else:
decimal_found = 1
elif x == "-" and allow_neg:
if negative_found:
return 0
else:
negative_found = 1
else:
return 0
return 1
Everything works just great, until I pass it a value like: 0.000085
When that happens str(.000085) returns 8.5e-05
I'm open to all suggestions at this point. I've also tried replacing
the "for" statement above with: for x in "%20.20f" % s:
But that no longer returns the decimal portion of the value.
Please CC me in your replies.
Thanks in advance,
Steve
More information about the Python-list
mailing list