1. Convert Using
Double.parseDouble()
String text = "12.34"; // example String
double value = Double.parseDouble(text);
Double.parseValueOf()
String numberAsString = "153.25"; double number = Double.valueOf(numberAsString); System.out.println("The number is: " + number);
3. Convert Using
new Double().doubleValue()
String numberAsString = "153.25"; Double doubleObject = new Double(numberAsString); double number = doubleObject.doubleValue();
4. Convert Using
java.text.DecimalFormat
String numberAsString = "153.25"; DecimalFormat decimalFormat = new DecimalFormat("#"); try { double number = decimalFormat.parse(numberAsString).doubleValue(); System.out.println("The number is: " + number); } catch (ParseException e) { System.out.println(numberAsString + " is not a valid number."); }
0 komentar:
Post a Comment