JS数字转换金额格式方法(千分符,中文大写)

更新时间:2023-07-26 19:19:21 阅读: 评论:0

上⾯的各种⽅法直接传⼊对应参数,就可以输出你期望的千分符格式的数字了。数字格式转换中⽂⼤写格式
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;

本文发布于:2023-07-26 19:19:21,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1118677.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:数字   部分   单位
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图