Convert float to string ...

Discussion in 'Python' started by =?ISO-8859-1?Q?Konrad_M=FChler?=, Aug 23, 2005.

  1. Hi,

    a simple question but i found no solution:

    How can i convert a float value into a string value?


    string_value1 = string(float_value) + ' abc'


    doesn't work ...

    Thanks
    Konrad
     
    =?ISO-8859-1?Q?Konrad_M=FChler?=, Aug 23, 2005
    #1
    1. Advertisements

  2. =?ISO-8859-1?Q?Konrad_M=FChler?=

    Matt Hammond Guest

    How can i convert a float value into a string value?

    Try:
    string_value1 = str(float_value) + ' abc'
    or:
    string_value1 = repr(float_value) + ' abc'


    Type in an interactive python session.
    help(str)
    or:
    help(repr)


    regards


    Matt
     
    Matt Hammond, Aug 23, 2005
    #2
    1. Advertisements

  3. string_value1 = str(float_value) + ' abc'

    Or the more versatile:

    string_value1 = "%10.3f abc" % float_value
     
    Grant Edwards, Aug 23, 2005
    #3
  4. string_value1 = str(float_value) + ' abc'
     
    Simon Brunning, Aug 23, 2005
    #4
  5. str(float_value) + 'abc'

    repr(float_value) + "abc"

    '%fabc' % float_value

    '%gabc' % float_value

    (etc)

    the tutorial has more information:

    http://docs.python.org/tut/node9.html

    </F>
     
    Fredrik Lundh, Aug 23, 2005
    #5
  6. =?ISO-8859-1?Q?Konrad_M=FChler?=

    deelan Guest

    just use the "str" built-in type:
    '9.99'
     
    deelan, Aug 23, 2005
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.