Package shared.number

Source Code of shared.number.JDoubleHelper

/** Created on 06.11.2008 11:40:06
*
* Copyright (C) 2008  PSYSTEME GmbH  Georg-Hallmaier-Str. 6  D-81369 Muenchen.
*
* @author reiner
*/

package shared.number;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Locale;

/**
* Parse a double value from a string using the us locale (.)
* and a defined locale
*/
public final class JDoubleHelper
{
    private JDoubleHelper()
    {}
   
    public static double parseDouble(String str, Locale locale) throws NumberFormatException
    {
        double val;
        try
        {
            val = Double.parseDouble(str);
        }
        catch(NumberFormatException ex)
        {
            try
            {
                NumberFormat numberFormat = NumberFormat.getInstance(locale);
                val = numberFormat.parse(str).doubleValue();
            }
            catch(ParseException e)
            {
                throw new NumberFormatException(e.getMessage());
            }
        }
        return val;
    }
   
    public static double parseDouble(String str) throws NumberFormatException
    {
        return parseDouble(str, Locale.getDefault());
    }
}
TOP

Related Classes of shared.number.JDoubleHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.