Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.text.TextUtils;

import java.text.DecimalFormat;

public class Main {

    public static String formatMoney(double amount) {
        DecimalFormat df = new DecimalFormat();
        df.applyPattern("##,###0.00");
        return df.format(amount);
    }

    public static String formatMoney(String amount) {
        if (TextUtils.isEmpty(amount)) {
            return "0.00";
        }
        String result;
        try {
            double num = Double.parseDouble(amount);
            DecimalFormat formater = new DecimalFormat("###,##0.00");
            result = formater.format(num / 100.0d);
        } catch (NumberFormatException e) {
            result = amount;
        }
        return result;
    }
}