上⾯的各种⽅法直接传⼊对应参数,就可以输出你期望的千分符格式的数字了。数字格式转换中⽂⼤写格式
function capitalAmount(amount) {
// 汉字的数字
const cnNums = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"];
// 基本单位
const cnIntRadice = ["", "拾", "佰", "仟"];
// 对应整数部分扩展单位
const cnIntUnits = ["", "万", "亿", "兆"];
// 对应⼩数部分单位
const cnDecUnits = ["⾓", "分", "毫", "厘"];
// 整数⾦额时后⾯跟的字符
const cnInteger = "整";
// 整型完以后的单位
浣沙溪
const cnIntLast = "元";
津津有味的近义词
// 最⼤处理的数字
const maxNum = 9999999999999999.99;
// ⾦额整数部分
let integerNum;
// ⾦额⼩数部分
let decimalNum;
// 输出的中⽂⾦额字符串
let chineStr = "";
/
/ 分离⾦额后⽤的数组,预定义
let parts;
if (amount === "") { return ""; }
amount = parFloat(amount);
if (amount >= maxNum) {
// 超出最⼤处理数字
return "";出发作文800字
}游洞庭湖
自荐是什么意思
if (amount === 0) {
chineStr = cnNums[0] + cnIntLast + cnInteger;
return chineStr;
}
// 转换为字符串
amount = String();
if (amount.indexOf(".") === -1) {
猪瘦肉怎么做好吃
integerNum = amount;
decimalNum = "";
} el {
parts = amount.split(".");
integerNum = parts[0];
decimalNum = parts[1].substr(0, 4);
}
追梦的句子/
/ 获取整型部分转换
男士护肤品哪个好用if (parInt(integerNum, 10) > 0) {
let zeroCount = 0;
const IntLen = integerNum.length;
for (let i = 0; i < IntLen; i++) {
const n = integerNum.substr(i, 1);
const p = IntLen - i - 1;
const q = p / 4;
const m = p % 4;
if (n === "0") {
zeroCount++;
} el {
if (zeroCount > 0) {
chineStr += cnNums[0];
}
// 归零
zeroCount = 0;
chineStr += cnNums[parInt(n, 10)] + cnIntRadice[m];
}
if (m === 0 && zeroCount < 4) {
chineStr += cnIntUnits[q];
}
}
chineStr += cnIntLast;