Here you can find the source of unformatingDecimalNumber(String cadena, Locale locale, int maxIntPart, int maxFloatPart)
Parameter | Description |
---|---|
cadena | the string that contains the number |
locale | the locale |
maxIntPart | this the max of digits on the integer part |
maxFloatPart | this the max of digits on the decimal part |
public static BigDecimal unformatingDecimalNumber(String cadena, Locale locale, int maxIntPart, int maxFloatPart)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.text.NumberFormat; import java.text.ParseException; import java.util.*; public class Main { /**// w w w . jav a 2 s . c o m * Translate an String to BigDecimal number. * * @param cadena the string that contains the number * @param locale the locale * @param maxIntPart this the max of digits on the integer part * @param maxFloatPart this the max of digits on the decimal part * @return the bigdecimal number */ public static BigDecimal unformatingDecimalNumber(String cadena, Locale locale, int maxIntPart, int maxFloatPart) { BigDecimal result = null; NumberFormat numberFormat = settingUpValuesOfFormat(locale, maxIntPart, maxFloatPart); if (null != cadena && !"".equals(cadena.trim())) { try { Number number = numberFormat.parse(cadena); result = new BigDecimal(Double.toString(number.doubleValue())); } catch (ParseException e) { } } return result; } /** * Setting up the values for the instance an numberformat * * @param locale the locale * @param maxIntPart this the max of digits on the integer part * @param maxFloatPart this the max of digits on the decimal part * @return numberformat */ private static NumberFormat settingUpValuesOfFormat(Locale locale, int maxIntPart, int maxFloatPart) { NumberFormat numberFormat = NumberFormat.getInstance(locale); numberFormat.setMaximumFractionDigits(maxFloatPart); numberFormat.setMaximumIntegerDigits(maxIntPart); return numberFormat; } }