Java Number Format Pattern formatDollarTd(Object obj)

Here you can find the source of formatDollarTd(Object obj)

Description

format Dollar Td

License

Apache License

Declaration

public static String formatDollarTd(Object obj) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

import java.math.BigDecimal;

public class Main {
    public static String formatDollarTd(Object obj) {
        String out = "<td style='text-align:right'>";
        String strDollarAmt = formatDollar(obj);
        if (strDollarAmt.length() == 0) {
            // if you don't put a "non-breaking space" in an empty td/cell, 
            // the cell's border doesn't show !
            out += "&nbsp;";
        } else {//from   ww w.j av a2s . c  om
            out += strDollarAmt;
        }
        out += "</td>";
        return out;
    }

    public static String formatDollar(Object obj) {
        // null gets converted to empty string
        if (obj == null) {
            return "";
        }
        BigDecimal bd = (BigDecimal) obj;
        try {
            DecimalFormat intFormat = new DecimalFormat("$###,###,###,##0.00");
            return intFormat.format(bd);
        } catch (Exception e) {
            return "bad Dollar Amount in FormatUtils:" + obj.toString() + " Error:" + e.getMessage();
        }
    }
}

Related

  1. formatBytes(long bytes)
  2. formatBytes(long numBytes)
  3. formatDashboardNumber(Number amount)
  4. formatDisplay(String displayString)
  5. formatDollar(Object obj)
  6. formatFileLength(long length)
  7. formatGopNumber(Number gop)
  8. formatI18N(Object ob)
  9. formatiereSpeichergroesse(long bytes)