Java Decimal Format getDoubleFromTaxSet(String taxSetValue)

Here you can find the source of getDoubleFromTaxSet(String taxSetValue)

Description

get double value from arbitrary String represent a double (0,00) or (0.00)

License

Apache License

Parameter

Parameter Description
taxSetValue double value as String

Exception

Parameter Description
Exception an exception

Return

double value

Declaration

public static double getDoubleFromTaxSet(String taxSetValue) throws Exception 

Method Source Code

//package com.java2s;
/*// w w w. j  a va  2  s  .  com
 * Copyright (C) 2015
 * A-SIT Plus GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.text.*;

import java.util.Locale;

public class Main {
    /**
     * get double value from arbitrary String represent a double (0,00) or (0.00)
     *
     * @param taxSetValue double value as String
     * @return double value
     * @throws Exception
     */
    public static double getDoubleFromTaxSet(String taxSetValue) throws Exception {
        //try format ("0,00")
        NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
        DecimalFormat decimalFormat = (DecimalFormat) nf;
        Exception parseException;
        try {
            return decimalFormat.parse(taxSetValue).doubleValue();
        } catch (ParseException ignored) {
        }
        //if Austrian/German format fail, try US format (0.00)
        nf = NumberFormat.getNumberInstance(Locale.US);
        decimalFormat = (DecimalFormat) nf;
        try {
            return decimalFormat.parse(taxSetValue).doubleValue();
        } catch (ParseException e) {
            parseException = e;
        }
        throw parseException;
    }
}

Related

  1. getDoubleAsString(double value)
  2. getDoubleByNumeric(String valorTexto)
  3. getDoubleDecimalNumber(double d)
  4. getDoubledigit(double f)
  5. getDoubleForDisplay(Double d)
  6. getDoubleWithTwoDecimalDigits(double value)
  7. getDurationString(double duration)
  8. getEngineeringNotation(final double d)
  9. getInteger(Double d)