Here you can find the source of formatingDecimalNumber(Object obj, Locale locale, int maxIntPart, int maxFloatPart)
Parameter | Description |
---|---|
obj | the object 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 Object formatingDecimalNumber(Object obj, Locale locale, int maxIntPart, int maxFloatPart)
//package com.java2s; //License from project: Open Source License import java.text.NumberFormat; import java.util.*; public class Main { /**// w w w .j a va 2 s. c om * formatting the object (obj) to a bigDecimal taking into account the locale * * @param obj the object 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 Object that contains the bigdecimal formatted for the views */ public static Object formatingDecimalNumber(Object obj, Locale locale, int maxIntPart, int maxFloatPart) { Object result = obj; NumberFormat numberFormat = settingUpValuesOfFormat(locale, maxIntPart, maxFloatPart); try { Double number = new Double(obj.toString()); result = numberFormat.format(number.doubleValue()); } catch (NumberFormatException 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; } }