Here you can find the source of format2Double(Double amount)
public static String format2Double(Double amount)
//package com.java2s; /**/* w w w. ja v a 2s .c o m*/ * ============================================================================== * Copyright (c) 2015 by www.dianxin.com, All rights reserved. * ============================================================================== * This software is the confidential and proprietary information of * tencent.com, Inc. ("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 dianxin.com, Inc. * ------------------------------------------------------------------------------ * <p/> * Author: faberxu * Date: 2015/12/18 * Description: ?????? * Nothing. * Function List: * 1. Nothing. * History: * 1. Nothing. * ============================================================================== */ import java.math.BigDecimal; import java.text.DecimalFormat; public class Main { public static String format2Double(Double amount) { return formatDouble(amount, "0.00"); } public static String formatDouble(Double amount, int scale) { if (null == amount) { return "--"; } BigDecimal decimal = new BigDecimal(Double.toString(amount)).setScale(scale, BigDecimal.ROUND_HALF_UP); return decimal.toString(); } public static String formatDouble(Double amount) { return formatDouble(amount, 2); } public static String formatDouble(Double amount, String pattern) { if (null == amount) { return "--"; } DecimalFormat df = new DecimalFormat(pattern); return df.format(amount); } public static String format(String s, Object obj) { if (null == obj) { return "--"; } return String.format(s, obj); } }