Here you can find the source of doubleFormat(Double d)
Parameter | Description |
---|---|
d | Double to format |
public static String doubleFormat(Double d)
//package com.java2s; //License from project: Apache License import java.text.NumberFormat; public class Main { /**//from www . j a v a 2s . c o m * Formats a double to two decimal places * * @param d Double to format * @return Formatted double */ public static String doubleFormat(Double d) { return doubleFormat(d, 0); } public static String doubleFormat(double d) { return doubleFormat(new Double(d)); } public static String doubleFormat(Double d, int minFraction) { if (d == null) { return null; } NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); if (minFraction > 0) { nf.setMinimumFractionDigits(minFraction); } return nf.format(d); } public static String doubleFormat(double d, int minFraction) { return doubleFormat(new Double(d), minFraction); } }