File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Float.parseFloat - nothing happens Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Float.parseFloat - nothing happens" Watch "Float.parseFloat - nothing happens" New topic

Float.parseFloat - nothing happens

Soenke Klinkhammer

Joined: Oct 21, 2001
Posts: 9
hey folks
I'm having a problem with the Float.parseFloat(String s) method.

This sample Applet is fairly simple: the user enters some (float)value in the textfield,
and that String then gets converted to a float. After that, the square of the float is shown
in the label. For some reason I haven't found yet, the Applet doesn't react at all when the button
is pressed. If i replace the Float.parseFloat with the parseInt argument, it works fine (except for the
fact that the user has to enter integers - I know that I forgot to put all that in a try-catch method...let's just assume the user enters
number values).
Furthermore, I'm looking for a way to replace a char within a string with a new char ("," with ".").
I tried the string.replace(oldchar, newchar) method, but it doesnt work. I was planning on putting that
method in the KeyListener-method keyPressed or in the TextListener-method textValueChanged.Would be very nice, if you could tell me a better way to do it (if there is a better way...=).
Thanks in advance,
(edited by Cindy to format code)

[This message has been edited by Cindy Glass (edited November 08, 2001).]
Kris Nelson
Ranch Hand

Joined: Nov 04, 2001
Posts: 35
The code works fine when I cut & paste and compile it. I entered 2.5 and clicked the button, 6.25 came in the label. I entered 10.0 and I got 100.0.
Are you using the appletviewer or a browser to test it (just curious)?
Java/XML Web Development
Check it out!
[This message has been edited by Kris Nelson (edited November 08, 2001).]<br />Java/XML Web Development<br />Check it out!<br /><a href="" target="_blank" rel="nofollow"></a>
Soenke Klinkhammer

Joined: Oct 21, 2001
Posts: 9
I forgot to mention that I'm trying to get it to work on my IE5. So, I didn't mention that it worked fine in the appletviewer.
BUT: hey, I found the error/ source of my problem - parseFloat is not supported by IE5, because it came out with JDK 1.2.
Thanks to all those who would have helped me =)
I agree. Here's the link:
subject: Float.parseFloat - nothing happens
It's not a secret anymore!