Here you can find the source of removeTrailingZeroes(BigDecimal value, boolean isCurrency)
Parameter | Description |
---|---|
value | a parameter |
isCurrency | a parameter |
public static BigDecimal removeTrailingZeroes(BigDecimal value, boolean isCurrency)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; import java.text.DecimalFormat; public class Main { /**/*from w w w. ja v a 2 s .c o m*/ * Convert BigDecimal to currency or quantity. Currency has always at least 2 fractions and quantity 0 or more. Maximum precision allowed * is 6 decimal places (numbers after decimal point) * * @param value * @param isCurrency * @return value, with trailing zeroes removed */ public static BigDecimal removeTrailingZeroes(BigDecimal value, boolean isCurrency) { if (value == null) { return null; } DecimalFormat df; if (isCurrency) { df = new DecimalFormat("0.00####"); } else { df = new DecimalFormat("0.######"); } String format = df.format(value); return new BigDecimal(format.replace(",", ".")); } }