[Python-Dev] Re: [spambayes-dev] RE: RE: [Spambayes] Question (orpossibly a bug
report)
Scott David Daniels
Scott.Daniels@Acm.Org
Fri, 25 Jul 2003 06:17:50 -0700
I've been seeing a lot of "we'll have to use float(123)/100"
messages floating around, and I'd like to point out there is an
atof-able form for floating point numbers:
256.7654e-7 = 2567654e-11
def safestr(floatstr):
"""Return a locale-safe version of C-locale-generated floatstr"""
try:
decpos = floatstr.index('.')
except ValueError:
return floatstr
try:
exppos = floatstr.lower().index('e')
except ValueError:
ebias = 0
exppos = len(sv)
else:
ebias = int(floatstr[exppos+1:])
return '%s%se%s' % (floatstr[:decpos], floatstr[decpos+1:exppos],
ebias + 1 - exppos + decpos)
floating-point-need-not-use-fractional-mantissas-ly yours,
-Scott David Daniels