js阿拉伯数字转换为中文大写
时间: 2023-09-04 13:10:55 浏览: 67
以下是将JS中的阿拉伯数字转换为中文大写的代码:
```javascript
function numberToChinese(num) {
var chineseNumArr = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
var chineseUnitArr = ["", "十", "百", "千", "万", "亿", "兆"];
var chineseStr = "";
var unitPos = 0;
var needZero = false;
if (num === 0) {
return chineseNumArr[0];
}
while (num > 0) {
var digit = num % 10;
if (digit === 0) {
if (needZero) {
chineseStr = chineseNumArr[digit] + chineseStr;
}
needZero = true;
} else {
chineseStr = chineseNumArr[digit] + chineseUnitArr[unitPos] + chineseStr;
needZero = false;
}
unitPos++;
num = Math.floor(num / 10);
}
return chineseStr;
}
```
这个函数将会把阿拉伯数字转换成中文大写。例如,输入数字12345,输出字符串"一万二千三百四十五"。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)