Results 1 to 5 of 5

Thread: Float to String

  1. #1
    mew
    mew is offline Member
    Join Date
    Nov 2007
    Posts
    70
    Rep Power
    0

    Default Float to String

    Java Code:
    float f = 10.23f;
    I want to convert this float to a String. How to do this.

    Thanks in advance

  2. #2
    beserie is offline Member
    Join Date
    Dec 2007
    Posts
    5
    Rep Power
    0

    Default

    to ways to do this.....

    Just use it as a string.... As in this example :

    String str;
    float f = 12.23;
    str = "bla bla bla"+f;

    the result is a string containing "bla bla bla12.23"
    if you just want the float, juste concatenate it to an empty string (str= ""+f; )

    OR
    explicitly transform it using the appropriate method :
    str = f.toString();

    ET C'EST CAISSE ;-)

  3. #3
    beserie is offline Member
    Join Date
    Dec 2007
    Posts
    5
    Rep Power
    0

    Default

    You have to consider de float F as an object of the Float class.
    because it IS an object of that class.

    then check : Float (Java 2 Platform SE v1.4.2)

    to know all you can do with that object.

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default

    You can do String.valueOf(float);

  5. #5
    mew
    mew is offline Member
    Join Date
    Nov 2007
    Posts
    70
    Rep Power
    0

Similar Threads

  1. String to Float
    By durahman in forum New To Java
    Replies: 2
    Last Post: 02-12-2008, 01:17 AM
  2. convert string to float
    By miss_dot in forum NetBeans
    Replies: 1
    Last Post: 11-15-2007, 12:26 AM
  3. Error with convert to Float
    By cachi in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 03:18 AM
  4. Help with valid declarations of a float
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 11:28 AM
  5. Class float
    By Peter in forum New To Java
    Replies: 1
    Last Post: 07-08-2007, 02:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •