Here you can find the source of getDoubleFromTaxSet(String taxSetValue)
Parameter | Description |
---|---|
taxSetValue | double value as String |
Parameter | Description |
---|---|
Exception | an exception |
public static double getDoubleFromTaxSet(String taxSetValue) throws Exception
//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; } }