Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.text.NumberFormat;

public class Main {
    public static final long NumEmpty = Long.MIN_VALUE + 988;

    public static String getBalanceDisplay(String bal, int floatSize) {
        if ("".equals(bal)) {
            return "";
        } else {
            long amount = Long.parseLong(bal);
            NumberFormat format = NumberFormat.getInstance();
            if (NumEmpty == amount)
                return "";
            if (floatSize < 0) { // error input
                return Long.toString(amount);
            }
            if (floatSize == 2) {
                boolean zs = true;
                if (amount < 0) {
                    zs = false;
                    amount = -amount;
                }
                long m = amount / 100;
                long f = amount - m * 100;
                return (zs ? "" : "-") + format.format(m) + "." + (f > 9 ? Long.toString(f) : "0" + f);
            } else if (floatSize == 0) {
                return format.format(amount);
            } else { // error input
                return format.format(amount);
            }
        }
    }

    public static String getBalanceDisplay(long amount, int floatSize) {
        NumberFormat format = NumberFormat.getInstance();
        if (NumEmpty == amount)
            return "";
        if (floatSize < 0) { // error input
            return Long.toString(amount);
        }
        if (floatSize == 2) {
            boolean zs = true;
            if (amount < 0) {
                zs = false;
                amount = -amount;
            }
            long m = amount / 100;
            long f = amount - m * 100;
            return (zs ? "" : "-") + format.format(m) + "." + (f > 9 ? Long.toString(f) : "0" + f);
        } else if (floatSize == 0) {
            return format.format(amount);
        } else { // error input
            return format.format(amount);
        }
    }
}