Converting floating point to string in non-scientific format

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

    #1

    Converting floating point to string in non-scientific format

    Hi all:

    When I try to convert a float variable into string via repr() or str()
    function, i get the value as is, i.e '0.1e-7' in IEEE 754 format.
    Instead how can force the created string to represent the floating
    point in non-scientific fashion (non IEEE 754 format)? i.e
    something like 0.000000001

    Thanks in advance for your help.

    -Madhu
  • Dan Bishop

    #2
    Re: Converting floating point to string in non-scientific format

    Madhusudhanan Chandrasekaran wrote:[color=blue]
    > Hi all:
    >
    > When I try to convert a float variable into string via repr() or str()
    > function, i get the value as is, i.e '0.1e-7' in IEEE 754 format.
    > Instead how can force the created string to represent the floating
    > point in non-scientific fashion (non IEEE 754 format)? i.e
    > something like 0.000000001[/color]

    Use the % operator with the f format (e.g., '%.7f' % x).

    Comment

    • ernesto.adorio@gmail.com

      #3
      Re: Converting floating point to string in non-scientific format

      See also non-exponential floating point representation in
      http://aspn.activestate.com/ASPN/Coo.../Recipe/358361 by R.
      Hettinger.

      Comment

      Working...