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:float string and returns its value. * * @param s * A string representation of an xsd:float value. * @return The <tt>float</tt> value represented by the supplied string argument. * @throws NumberFormatException * If the supplied string is not a valid xsd:float value. */ public static float parseFloat(String s) { if (POSITIVE_INFINITY.equals(s)) { return Float.POSITIVE_INFINITY; } else if (NEGATIVE_INFINITY.equals(s)) { return Float.NEGATIVE_INFINITY; } else if (NaN.equals(s)) { return Float.NaN; } else { s = trimPlusSign(s); return Float.parseFloat(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; } } }