Converting a string to integer/float

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ikot

    Converting a string to integer/float

    Hello,
    I am stuck with a problem, might be very trivial, to ask here, but
    dont find a way out. I read a string like 12345.678 from a text file,
    which will be string for me, but how do I convert it into a float for
    my use ?
    Thanks
    Ikot
  • Paul Rubin

    #2
    Re: Converting a string to integer/float

    aprogrammer@fas tmail.fm (Ikot) writes:[color=blue]
    > I am stuck with a problem, might be very trivial, to ask here, but
    > dont find a way out. I read a string like 12345.678 from a text file,
    > which will be string for me, but how do I convert it into a float for
    > my use ?[/color]

    s = '12345.678'
    x = float(s)

    Comment

    • James Henderson

      #3
      Re: Converting a string to integer/float

      On Thursday 22 January 2004 3:43 am, Ikot wrote:[color=blue]
      > Hello,
      > I am stuck with a problem, might be very trivial, to ask here, but
      > dont find a way out. I read a string like 12345.678 from a text file,
      > which will be string for me, but how do I convert it into a float for
      > my use ?
      > Thanks
      > Ikot[/color]

      float is a builtin type that can be constructed from a string:
      [color=blue][color=green][color=darkred]
      >>> float('12345.67 8')[/color][/color][/color]
      12345.678

      You'd probably find it helpful to work your way through:



      James
      --
      James Henderson, Logical Progression Ltd.

      Download MailManager for free. MailManager is designed to solve the problems companies have as the volumes of email they receive increase such as making sure email goes to the right person, making sure it is answered on time, ensuring information in email boxes is shared within th



      Comment

      Working...