format Dollar - Java java.lang

Java examples for java.lang:int Format

Description

format Dollar

Demo Code


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

import java.math.BigDecimal;

public class Main {
    public static String formatDollar(Object obj) {
        String out = "";
        if (obj == null) {
            return out;
        }/*from  w  w  w  .  jav  a2  s.com*/
        BigDecimal bd = (BigDecimal) obj;
        try {
            DecimalFormat intFormat = new DecimalFormat(
                    "$###,###,###,##0.00");
            out = (new StringBuilder()).append(out)
                    .append(intFormat.format(bd)).toString();
        } catch (Exception e) {
            out = (new StringBuilder()).append(out)
                    .append("bad Dollar Amount in FormatUtils:")
                    .append(obj.toString()).append(" Error:")
                    .append(e.getMessage()).toString();
        }
        return out;
    }
}

Related Tutorials