Java Money Format beautifyMoney(long money)

Here you can find the source of beautifyMoney(long money)

Description

beautify Money

License

Open Source License

Declaration

public static String beautifyMoney(long money) 

Method Source Code

//package com.java2s;

public class Main {
    public static String beautifyMoney(long money) {
        String res = "";
        String tmp = String.valueOf(money);
        Boolean isNegative = false;
        if (tmp.indexOf("-") >= 0) {
            isNegative = true;/*w  w w  .  ja v a2 s  .  c o  m*/
            tmp = tmp.replace("-", "");
        }
        int length = tmp.length();

        int count = 0;
        for (int i = length - 1; i >= 0; i--) {
            if (i < length - 1 && count % 3 == 0) {
                res = "." + res;
            }

            res = tmp.charAt(i) + res;
            count++;
        }
        if (isNegative) {
            res = '-' + res;
        }
        return res;
    }
}

Related

  1. format(Object money)
  2. format2Money(double value)
  3. formatBookkeeperMoney(double cents, Locale locale)
  4. formatDoubleToMoneyString(double num)