package com.engine.salary.report.util;

import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.regex.Pattern;

public class ReportDataUtil {

    private static final DecimalFormat decimalFormat = new DecimalFormat("#,##0.00");

    private static final DecimalFormat decimalFormatSp = new DecimalFormat("#,##0.000");

    public static String thousandthConvert(String originString) {
        if (StringUtils.isNotEmpty(originString)) {
            if (originString.contains(".") && (originString.split("\\.")[1]).length() == 3) {
                return decimalFormatSp.format(Double.valueOf(originString));
            }
            return decimalFormat.format(Double.valueOf(originString));
        }
        return "0.00";
    }

    public static boolean zeroJudge(BigDecimal bigDecimal) {
        return Pattern.compile("[0|.]*").matcher(bigDecimal.toPlainString()).matches();
    }

    public static boolean zeroJudge(String data) {
        return Pattern.compile("[0|.]*").matcher(data).matches();
    }

}
