Java BigDecimal Format formatBigDecimalWithPrecise(BigDecimal number)

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

Description

format bigdecimal to string

License

Open Source License

Parameter

Parameter Description
number bigdecimal converted to string

Return

String

Declaration

public static String formatBigDecimalWithPrecise(BigDecimal number) 

Method Source Code

//package com.java2s;
/*/* w ww  .j ava  2  s .c  o m*/
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

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

import java.math.BigDecimal;

public class Main {
    /**
     * format bigdecimal to string
     *
     * @param number bigdecimal converted to string
     * @return <code>String</code>
     */
    public static String formatBigDecimalWithPrecise(BigDecimal number) {
        String result = "";
        NumberFormat nbf = new DecimalFormat("#,##0.00");
        if (number != null) {
            result = nbf.format(number.doubleValue());
        }
        return result;
    }

    /**
     * format bigdecimal to string with specified pattern
     *
     * @param number  bigdecimal converted to string
     * @param pattern specified pattern
     * @return <code>String</code>
     */
    public static String formatBigDecimalWithPrecise(BigDecimal number, String pattern) {
        String result = "";
        NumberFormat nbf = new DecimalFormat(pattern);
        if (number != null) {
            result = nbf.format(number.doubleValue());
        }
        return result;
    }
}

Related

  1. formatBigDecimal(BigDecimal n, int dp)
  2. formatBigDecimal(BigDecimal number, int val)
  3. formatBigDecimal(BigDecimal valor, int decimal)
  4. formatBigDecimal(BigDecimal value, char thousandSep, char decimalPoint, int numDecimals)
  5. formatBigDecimal(String value)
  6. formatCents(int cents)
  7. formatCUBRIDNumber(BigDecimal value)
  8. formatDecimal(BigDecimal b)
  9. formatDecimal(BigDecimal num)