Here you can find the source of formatBigDecimalWithPrecise(BigDecimal number)
Parameter | Description |
---|---|
number | bigdecimal converted to string |
String
public static String formatBigDecimalWithPrecise(BigDecimal number)
//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; } }