Here you can find the source of format2CurrencyWithComma(double amt)
Parameter | Description |
---|---|
amt | a parameter |
public static String format2CurrencyWithComma(double amt)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { /**//from ww w . j a va2 s . c om * @param amt * @return The return result will be formatted as ($###,###,###.##) */ public static String format2CurrencyWithComma(double amt) { String formattedAmount = format2DecimalPointMoneyWithComma(amt); if (formattedAmount.startsWith("(")) { return formattedAmount.replace("(", "($"); } else { return "$" + formattedAmount; } } /** * @param amt * @return The return result will be formatted as (###,###,###.##) */ public static String format2DecimalPointMoneyWithComma(double amt) { boolean isNegativ = (amt < 0); String tmp = formatDouble(Math.abs(amt)); if (isNegativ) return "(" + tmp + ")"; else return tmp; } public static String formatDouble(double value) { NumberFormat formatter = new DecimalFormat("#,###,##0.00;(#,###,##0.00)"); return formatter.format(value); } }