选址阶段
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
* @FileName: NumberConverter
|
||||
* @Description:
|
||||
* @date 2024-04-10 17:07
|
||||
*/
|
||||
public class NumberConverter {
|
||||
|
||||
private static final char[] CN_NUMBERS = {'零', '一', '二', '三', '四', '五', '六', '七', '八', '九'};
|
||||
private static final char[] CN_UNITS = {'个', '十', '百', '千', '万'};
|
||||
public static String convertArabicToChinese(int number) {
|
||||
String result = "";
|
||||
// 将数字转换为字符串
|
||||
String numStr = String.valueOf(number);
|
||||
int len = numStr.length();
|
||||
boolean lastIsZero = false;
|
||||
for (int i = 0; i < len; i++) {
|
||||
int n = numStr.charAt(i) - '0'; // 转换为数字
|
||||
if (n != 0 || (!lastIsZero && i != len - 1)) {
|
||||
result += CN_NUMBERS[n]; // 转换为中文数字
|
||||
if (i != len - 1) {
|
||||
// 不是最后一位数字,需要添加单位
|
||||
result += CN_UNITS[(len - 1 - i)];
|
||||
}
|
||||
} else {
|
||||
lastIsZero = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user