Format an amount of money in double. - Java java.lang

Java examples for java.lang:double Format

Description

Format an amount of money in double.

Demo Code


//package com.java2s;
import java.text.DecimalFormat;

public class Main {
    public static void main(String[] argv) {
        double amount = 42.45678;
        System.out.println(formatAmount(amount));
    }/* w  ww  .j  a v a 2  s .  c  om*/

    /**
     * Format an amount of money.
     * @param amount Amount of money
     * @return
     */
    public static String formatAmount(double amount) {
        return new DecimalFormat("0.00").format(amount);
    }
}

Related Tutorials