Java BigDecimal to String bigDecimalToString(BigDecimal number)

Here you can find the source of bigDecimalToString(BigDecimal number)

Description

big Decimal To String

License

Apache License

Declaration

public static String bigDecimalToString(BigDecimal number) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;

import java.util.Locale;

public class Main {
    public static String bigDecimalToString(BigDecimal number) {

        DecimalFormatSymbols symbols = new DecimalFormatSymbols(new Locale("pt", "BR"));
        symbols.setDecimalSeparator(',');
        symbols.setCurrencySymbol("");

        DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance(new Locale("pt", "BR"));
        decimalFormat.setDecimalFormatSymbols(symbols);
        decimalFormat.setGroupingUsed(false);
        decimalFormat.setParseBigDecimal(true);
        decimalFormat.setMinimumFractionDigits(2);
        decimalFormat.setMaximumFractionDigits(10);

        return decimalFormat.format(number).trim();
    }//from   ww w.  j  a  v a  2 s.c  om
}

Related

  1. bigDecimal2String(BigDecimal value)
  2. bigDecimal2String(BigDecimal value)
  3. bigDecimaltoString(BigDecimal bd)
  4. print(String tag, BigDecimal[][] a)