Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Distribution License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/org/documents/edl-v10.php. *******************************************************************************/ public class Main { public static final String POSITIVE_INFINITY = "INF"; public static final String NEGATIVE_INFINITY = "-INF"; public static final String NaN = "NaN"; /** * Parses the supplied xsd:double string and returns its value. * * @param s * A string representation of an xsd:double value. * @return The <tt>double</tt> value represented by the supplied string argument. * @throws NumberFormatException * If the supplied string is not a valid xsd:double value. */ public static double parseDouble(String s) { if (POSITIVE_INFINITY.equals(s)) { return Double.POSITIVE_INFINITY; } else if (NEGATIVE_INFINITY.equals(s)) { return Double.NEGATIVE_INFINITY; } else if (NaN.equals(s)) { return Double.NaN; } else { s = trimPlusSign(s); return Double.parseDouble(s); } } /** * Removes the first character from the supplied string if this is a plus sign ('+'). Number strings with * leading plus signs cannot be parsed by methods such as {@link Integer#parseInt(String)}. */ private static String trimPlusSign(String s) { if (s.length() > 0 && s.charAt(0) == '+') { return s.substring(1); } else { return s; } } }