java判断数字类型(小数和整数)

来源:互联网 发布:天猫淘宝白菜群 编辑:程序博客网 时间:2024/06/13 02:37
public static void main(String[] args) {
        value = Double.parseDouble(ss);
        String str = "0.2";
        System.out.println((int) Math.floor(1.6));
        System.out.println((int) (0.6));
        System.out.println(Math.round(0.3));
        Pattern pattern = Pattern.compile("^\\d+$|^\\d+\\.\\d+$|-\\d+$");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            System.out.println(false);
        } else {
            System.out.println(true);
        }
    }

原创粉丝点击