显示数字格式化以万、亿为单位转换

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38875767/article/details/85284045
public class NumberUtils {
    /**
     * 判断是否为纯数字
     *
     * @param str ,需要检查的字符
     */
    public static boolean isNumbericString(String str) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        Pattern p = Pattern.compile("^[0-9]+$");
        Matcher m = p.matcher(str);
        return m.find();
    }

    /**
     * 数字格式转换,大于万的数字展示为 xx万
     *
     * @param num ,需要检查的字符
     */
    public static String numberFormat(int num) {
        if (num <= 10000) {
            return String.valueOf(num);
        } else {
            return Math.floor(num) + "万";
        }
    }

    public static float minMax(float min, float value, float max) {
        value = Math.min(value, max);
        value = Math.max(min, value);
        return value;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_38875767/article/details/85284045