Java开发 之小数点保留后两位、千分位符、实数正则校验
2021/10/12 17:15:47
本文主要是介绍Java开发 之小数点保留后两位、千分位符、实数正则校验,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import java.util.regex.Pattern; public class DefaultTest { private static final Pattern PATTERN = Pattern.compile("^[-]?(\\d{1,3}(,\\d{3})*(\\.\\d{1,2})?)"); public static void main(String[] args) { System.out.println("5 === " + PATTERN.matcher("5").matches()); System.out.println("5. === " + PATTERN.matcher("5.").matches()); System.out.println("5.1 === " + PATTERN.matcher("5.1").matches()); System.out.println("5.12 === " + PATTERN.matcher("5.12").matches()); System.out.println("5.123 === " + PATTERN.matcher("5.123").matches()); System.out.println("0.12 === " + PATTERN.matcher("0.12").matches()); System.out.println("1,006.12 === " + PATTERN.matcher("1,006.12").matches()); System.out.println("1,006.123 === " + PATTERN.matcher("1,006.123").matches()); System.out.println("1,006. === " + PATTERN.matcher("1,006.").matches()); System.out.println("1,006.1 === " + PATTERN.matcher("1,006.1").matches()); System.out.println("51,006.1 === " + PATTERN.matcher("51,006.1").matches()); System.out.println("3,541,006.1 === " + PATTERN.matcher("3,541,006.1").matches()); System.out.println("100446.12 === " + PATTERN.matcher("100446.12").matches()); System.out.println("10,06.1 === " + PATTERN.matcher("10,06.1").matches()); System.out.println("51,006.133 === " + PATTERN.matcher("51,006.133").matches()); System.out.println("3,541,006 === " + PATTERN.matcher("3,541,006").matches()); System.out.println("1,001 === " + PATTERN.matcher("1,001").matches()); System.out.println("-1,001 === " + PATTERN.matcher("-1,001").matches()); System.out.println("+1,001 === " + PATTERN.matcher("+1,001").matches()); System.out.println("3333,891,001 === " + PATTERN.matcher("3333,891,001").matches()); } }
5 === true 5. === false 5.1 === true 5.12 === true 5.123 === false 0.12 === true 1,006.12 === true 1,006.123 === false 1,006. === false 1,006.1 === true 51,006.1 === true 3,541,006.1 === true 100446.12 === false 10,06.1 === false 51,006.133 === false 3,541,006 === true 1,001 === true -1,001 === true +1,001 === false 3333,891,001 === false
这篇关于Java开发 之小数点保留后两位、千分位符、实数正则校验的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-15JavaMailSender是什么,怎么使用?-icode9专业技术文章分享
- 2024-11-15JWT 用户校验学习:从入门到实践
- 2024-11-15Nest学习:新手入门全面指南
- 2024-11-15RestfulAPI学习:新手入门指南
- 2024-11-15Server Component学习:入门教程与实践指南
- 2024-11-15动态路由入门:新手必读指南
- 2024-11-15JWT 用户校验入门:轻松掌握JWT认证基础
- 2024-11-15Nest后端开发入门指南
- 2024-11-15Nest后端开发入门教程
- 2024-11-15RestfulAPI入门:新手快速上手指南