Convert float to string

Discussion in 'Java' started by Jack, Mar 20, 2008.

  1. Jack

    Jack Guest

    hexcalc.java:119: toString() in java.lang.Object cannot be applied to
    (float)
    System.out.println (Math.toString(theExp));
    ^
    1 error


    theExp is of type float
    Any help would be greatly appreciated!
    Thanks
    Jack
    Jack, Mar 20, 2008
    #1
    1. Advertising

  2. Jack

    Siam Guest

    Jack wrote:
    > hexcalc.java:119: toString() in java.lang.Object cannot be applied to
    > (float)
    > System.out.println (Math.toString(theExp));
    > ^
    > 1 error
    >


    What are you trying to do? To print the float,
    System.out.println(theExp) will do. The toString method is a non-
    static method (which takes no arguments) that you call on objects...
    You've called it it statically on the Math class, passing it a
    primitive... Thats why the compiler's complained!
    Siam, Mar 20, 2008
    #2
    1. Advertising

  3. "Jack" <> writes:

    > hexcalc.java:119: toString() in java.lang.Object cannot be applied to
    > (float)
    > System.out.println (Math.toString(theExp));
    > ^
    > 1 error


    > theExp is of type float


    As was already said, just
    System.out.println(theExp)
    will do.

    You might have been thinking of
    Float.toString(float)
    There is no Math.toString(float).

    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Mar 20, 2008
    #3
  4. Jack

    Roedy Green Guest

    On Fri, 21 Mar 2008 03:37:55 +0800, "Jack" <> wrote,
    quoted or indirectly quoted someone who said :

    >hexcalc.java:119: toString() in java.lang.Object cannot be applied to
    >(float)
    > System.out.println (Math.toString(theExp));


    see http://mindprod.com/applet/converter.html
    for how to interconvert all the common types.

    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Mar 20, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Quinn

    Convert float to string

    Quinn, Aug 6, 2003, in forum: Java
    Replies:
    1
    Views:
    8,502
    Roedy Green
    Aug 6, 2003
  2. Andy
    Replies:
    7
    Views:
    6,226
    Roedy Green
    May 10, 2004
  3. bd
    Replies:
    0
    Views:
    597
  4. Carsten Fuchs
    Replies:
    45
    Views:
    1,486
    James Kanze
    Oct 8, 2009
  5. Daniel Firu
    Replies:
    2
    Views:
    244
    Jesús Gabriel y Galán
    Jan 17, 2009
Loading...

Share This Page