Java Money Format str2money(String str)

Here you can find the source of str2money(String str)

Description

strmoney

License

Apache License

Declaration

public static String str2money(String str) 

Method Source Code

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

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {
    public static String str2money(String str) {
        try {/*from   w  w w .ja va  2 s  . c  o  m*/
            double amt = Long.parseLong(str) / 100.0D;
            return formatMoney(amt);
        } catch (Exception e) {
            System.err.println(e);
        }
        return str;
    }

    public static String formatMoney(double d) {
        DecimalFormat format = (DecimalFormat) NumberFormat.getPercentInstance();
        format.applyPattern("###########0.00");
        return format.format(d);
    }

    public static String formatMoney(String money) {
        if (money == null)
            return "";
        try {
            money = money.trim();
            double d = Double.parseDouble(money);
            return formatMoney(d);
        } catch (Exception e) {
            System.err.println(e);
        }
        return money;
    }
}

Related

  1. formatThousandMoney(String moneyStr)
  2. getMoneyFormat(double money)
  3. getMoneyString(double money)
  4. hourAndMinutesToString(int hours, int minutes)
  5. moneyDelFormat(String s)
  6. toMemoryString(double bytes)
  7. toMemoryUnits(double value)
  8. toMoney(long amount)