Java Parse Double parseInternationalDouble(String number)

Here you can find the source of parseInternationalDouble(String number)

Description

parse a string and return the corresponding double value, it accepts comma or point as decimal separator

License

Open Source License

Parameter

Parameter Description
number the number with a point or a comma as decimal separator

Exception

Parameter Description
ParseException in case of errors

Return

the float value corresponding to the parsed string

Declaration

public static float parseInternationalDouble(String number) throws ParseException 

Method Source Code


//package com.java2s;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

public class Main {
    /**//w w  w . j av  a 2 s.co  m
     * parse a string and return the corresponding double value, it accepts
     * comma or point as decimal separator
     * 
     * @param number
     *            the number with a point or a comma as decimal separator
     * @return the float value corresponding to the parsed string
     * @throws ParseException
     *             in case of errors
     */
    public static float parseInternationalDouble(String number) throws ParseException {
        NumberFormat nffrench = NumberFormat.getInstance(Locale.FRENCH);
        NumberFormat nfus = NumberFormat.getInstance(Locale.US);

        Number numberToReturn = number.indexOf(',') != -1 ? nffrench.parse(number) : nfus.parse(number);
        return numberToReturn.floatValue();
    }
}

Related

  1. parseDouble(String str)
  2. parseDouble(String stringValue)
  3. parseDouble(String value)
  4. ParseDoubleEx(String s, double value_if_fault)
  5. parseDoubleInCurrentDefaultLocale(String text)
  6. parseToCientificNotation(double value)
  7. parseToEngineeringNotation(double val, int decimalHouses)
  8. parseYuanToYi(Double data)