Java Locale Format formatDecimal(BigInteger b)

Here you can find the source of formatDecimal(BigInteger b)

Description

format Decimal

License

Open Source License

Declaration

public static String formatDecimal(BigInteger b) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.math.BigInteger;

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

import java.util.Locale;

public class Main {
    public static String formatDecimal(BigDecimal b) {
        if (b == null) {
            return null;
        }/*from   w w  w  .  j a v  a  2s  . c  om*/
        Locale loc = new Locale("nl", "NL", "EURO");
        NumberFormat n = NumberFormat.getCurrencyInstance(loc);
        double doublePayment = b.doubleValue();
        String s = n.format(doublePayment);
        return s;
    }

    public static String formatDecimal(BigInteger b) {

        Locale loc = new Locale("nl", "NL", "EURO");
        NumberFormat n = NumberFormat.getCurrencyInstance(loc);
        double doublePayment = b.doubleValue();
        n.setMaximumFractionDigits(0);
        String s = n.format(doublePayment);
        return s;
    }

    public static String format(int amount) {
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
        otherSymbols.setDecimalSeparator(',');
        otherSymbols.setGroupingSeparator('.');
        DecimalFormat df = new DecimalFormat("###,###,###,##0", otherSymbols);
        return df.format(amount);
    }

    public static String format(BigInteger amount) {
        if (amount == null) {
            return null;
        }
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
        otherSymbols.setDecimalSeparator(',');
        otherSymbols.setGroupingSeparator('.');
        DecimalFormat df = new DecimalFormat("###,###,###,##0", otherSymbols);
        return df.format(amount);
    }
}

Related

  1. formatDate2String(Date date, String format)
  2. formatDateByFormat(Date date, String format)
  3. formatDateTime(final Date date)
  4. formatDateTime(java.util.Date date, String format, String locale, String timeZone)
  5. formatDateToSQLString(Date srcDate)
  6. formatDecimalDisplay(final double _numberToFormat, final String _formatToApply)
  7. formatDouble(double in)
  8. formatDouble(double inVal, int inDecs)
  9. formatDouble(Double localDouble, int scale)