Here you can find the source of formatCurrency(Double number)
Parameter | Description |
---|---|
number | a parameter |
public static String formatCurrency(Double number)
//package com.java2s; import java.text.DecimalFormat; public class Main { /**/*from w ww. j a v a 2 s.c om*/ * Formats double as a string with 2 decimal places * @param number * @return currencyString */ public static String formatCurrency(Double number) { DecimalFormat formatter = new DecimalFormat("0.00"); return formatter.format(number); } /** * Formats numeric string as a string with 2 decimal places * @param numberStr * @return currencyString */ public static String formatCurrency(String numberStr) { if (numberStr.matches("\\d+(.\\d+)?")) { return formatCurrency(Double.parseDouble(numberStr)); } return ""; } }