Files
ChopperBot/chopperbot-common/src/main/java/org/example/util/ChineseConvertUtil.java
2023-08-31 01:36:20 +08:00

39 lines
910 B
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package org.example.util;
/**
* @author Genius
* @date 2023/07/19 02:17
**/
/**
* 中文转化工具
*/
public class ChineseConvertUtil {
/**
* 中文数量单位转Int
* @param str 中文字符串 如“350.1万”
* @return
*/
public static int cnNumericUnitsToInt(String str){
String[] parts = str.split("(?<=\\d\\.\\d)(?=\\D)");
if(parts.length==2){
float num = Float.parseFloat(parts[0]);
switch (parts[1]){
case "亿":
return (int)num*100000;
case "":
return (int)num*10000;
case "":
return (int)num*1000;
case "":
return (int)num*100;
case "":
return (int)num;
}
}
return Integer.parseInt(str);
}
}