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 string to number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string to number" Watch "string to number" New topic

string to number

ngoc thai

Joined: Sep 08, 2001
Posts: 2
Dear JR members,
What is the best way to convert a string of digits to either an integer, float or double? Please advice.
Here are the two sample strings: "28769", "78.14159"
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
For the float, use the static method Float.parseFloat(String s)
for the int, use the static method Integer.parseInt(String s)
Each primitive wrapper class has a method like this.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Ngoc,
To format the float or double values you can use:
I agree. Here's the link:
subject: string to number
It's not a secret anymore!