Here you can find the source of readDoubleAsString(String doubleAsString)
Parameter | Description |
---|---|
doubleAsString | the double value as a string |
Parameter | Description |
---|---|
NumberFormatException | thrown if the double cannot be read as adouble |
public static double readDoubleAsString(String doubleAsString) throws NumberFormatException
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { /**//from ww w.ja v a2 s .co m * Method for reading a double value as a string which uses either "," or * "." as the decimal symbol. * * @param doubleAsString the double value as a string * @return the double value * @throws NumberFormatException thrown if the double cannot be read as a * double */ public static double readDoubleAsString(String doubleAsString) throws NumberFormatException { BigDecimal temp; try { temp = new BigDecimal(doubleAsString); } catch (NumberFormatException e) { doubleAsString = doubleAsString.replaceAll("\\.", ""); doubleAsString = doubleAsString.replaceAll(",", "\\."); try { temp = new BigDecimal(doubleAsString); } catch (NumberFormatException ex) { throw new NumberFormatException(doubleAsString + " cannot be read as a floating value!"); } } return temp.doubleValue(); } }