This entry is from http://www.devdaily.com/java/edu/qanda/pjqa00008.shtml
Two ways to convert number to String
Method 1: using String.valueOf()
String s = String.valueOf(i);
String s = String.valueOf(f); // float
String s = String.valueOf(d); // double
String s = String.valueOf(l); // long
Method 2: using toString() method of the numeric classes
String s = new Integer(i).toString(); // or Integer.toString(i)
String s = new Float(f).toString();
String s = new Double(d).toString();
String s = new Long(l).toString();
Convert String to number:
int anInt = Integer.parseInt("17");
double aDouble = Double.parseDouble("17");
NOTE: The methods above are not exhaustive. Googling will surely yield a few more ways to do conversion.
Showing posts with label conversion. Show all posts
Showing posts with label conversion. Show all posts
Monday, July 11, 2011
Wednesday, July 6, 2011
Java String <-> int conversion
To convert String to int:
Integer.parseInt("17");
To convert int to String:
Integer.toString(17);
Integer.parseInt("17");
To convert int to String:
Integer.toString(17);
Subscribe to:
Posts (Atom)