Programming tips… by hcj

VIEWS: 11 PAGES: 1

									Programming tips…

Converting Strings to Numbers
To convert a string value to a number (for example, to convert the String value in a text field to an int), use these methods. Assume the following declarations:
String s; int i; type int long float long l; float f; double d; Example statement

i = Integer.parseInt(s); l = Long.parseLong(s); f = Float.parseFloat(s);

double d = Double.parseDouble(s);

If s is null or not a valid representation of a number of that type, these methods will throw (generate) a NumberFormatException. See below.

-----------------------------------------------------------

Converting Numbers to Strings Int I; String s = String.valueOf(i);


								
To top