From 43d11becdfc0d7af00b10e91b962cd0c4738bbf1 Mon Sep 17 00:00:00 2001
From: fwq <582742538@qq.com>
Date: 星期一, 11 十二月 2023 10:41:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/com/hx/util/NumberUtil.java |   64 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/hx/util/NumberUtil.java b/src/main/java/com/hx/util/NumberUtil.java
index 27d25e0..9ed21d0 100644
--- a/src/main/java/com/hx/util/NumberUtil.java
+++ b/src/main/java/com/hx/util/NumberUtil.java
@@ -3,6 +3,8 @@
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.DecimalFormat;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * 鏁板瓧宸ュ叿
@@ -351,4 +353,66 @@
         return result2;
     }
 
+    /**
+     * 浠庡瓧绗︿覆涓彁鍙栧皬鏁�
+     * @param str
+     * @return
+     */
+    public static String getNumber(String str){
+        // 鎺у埗姝e垯琛ㄨ揪寮忕殑鍖归厤琛屼负鐨勫弬鏁�(灏忔暟)
+        Pattern p = Pattern.compile("(\\d+\\.\\d+)");
+        //Matcher绫荤殑鏋勯�犳柟娉曚篃鏄鏈夌殑,涓嶈兘闅忔剰鍒涘缓,鍙兘閫氳繃Pattern.matcher(CharSequence input)鏂规硶寰楀埌璇ョ被鐨勫疄渚�.
+        Matcher m = p.matcher(str);
+        //m.find鐢ㄦ潵鍒ゆ柇璇ュ瓧绗︿覆涓槸鍚﹀惈鏈変笌"(\\d+\\.\\d+)"鐩稿尮閰嶇殑瀛愪覆
+        if (m.find()) {
+            //濡傛灉鏈夌浉鍖归厤鐨�,鍒欏垽鏂槸鍚︿负null鎿嶄綔
+            //group()涓殑鍙傛暟锛�0琛ㄧず鍖归厤鏁翠釜姝e垯锛�1琛ㄧず鍖归厤绗竴涓嫭鍙风殑姝e垯,2琛ㄧず鍖归厤绗簩涓鍒�,鍦ㄨ繖鍙湁涓�涓嫭鍙�,鍗�1鍜�0鏄竴鏍风殑
+            str = m.group(1) == null ? "" : m.group(1);
+        } else {
+            //濡傛灉鍖归厤涓嶅埌灏忔暟锛屽氨杩涜鏁存暟鍖归厤
+            p = Pattern.compile("(\\d+)");
+            m = p.matcher(str);
+            if (m.find()) {
+                //濡傛灉鏈夋暣鏁扮浉鍖归厤
+                str = m.group(1) == null ? "" : m.group(1);
+            } else {
+                //濡傛灉娌℃湁灏忔暟鍜屾暣鏁扮浉鍖归厤,鍗冲瓧绗︿覆涓病鏈夋暣鏁板拰灏忔暟锛屽氨璁句负绌�
+                str = "";
+            }
+        }
+        return str;
+    }
+
+    /** 鏍¢獙瀛楃涓叉槸鍚︽暣鏁� */
+    public static boolean checkStrIsInt(String str){
+        if(StringUtils.isEmpty(str)){
+            return false;
+        }
+        try{
+            Integer.parseInt(str);
+            return true;
+        }catch (Exception e){
+            return false;
+        }
+    }
+
+    /**
+     * 瀛楃涓茶浆鏁村舰
+     * @param str
+     * @param defInt    榛樿鏁存暟
+     * @return
+     */
+    public static int strChangeInt(String str, Integer defInt){
+        if(defInt == null){
+            defInt = 0;
+        }
+        if(StringUtils.isEmpty(str)){
+            return defInt;
+        }
+        try{
+            return Integer.parseInt(str);
+        }catch (Exception e){
+            return defInt;
+        }
+    }
 }

--
Gitblit v1.8.0