[Baypiggies] scientific notation: string to int

Eric Edens eric.edens at gmail.com
Wed Dec 8 22:42:00 CET 2010


Any ideas for improvement?


def foo(baz):
  '''@param baz - string representation of
                  exp notation, ie "3.2E4" or "3.2E-4"
  '''
  base, exp = map(float,baz.split('E'))
  return base*10**exp


>>> foo ('2.96116E+11')
296116000000.0
>>> foo ('2.96116E-11')
2.96116e-11
>>> foo ('3.2E4')
32000.0


On Wed, Dec 8, 2010 at 1:24 PM, Bryce Verdier <bryceverdier at gmail.com>wrote:

> So I've been given a project for work, a large CSV file with many many
> numbers and such to parse through. The lines that look like this:
>
> b1021384-6633-4756-b3e1-c36d34c1dfd2, clientname_001,Thu Dec  2 00:00:00
> UTC 2010,2.96116E+11,0,0, Thu Dec  2 00:00:00 UTC 2010,577078067
> 20,15228831373,80966857300,
>
> so I'm curious if there is a way to turn the string of scientific notion
> into the actual numerical value?
>
> All ideas are welcomed and thank in advance,
>
> Bryce
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20101208/9d88f72b/attachment-0001.html>


More information about the Baypiggies mailing list