当前位置:网站首页>js把数字转大写
js把数字转大写
2022-07-23 23:19:00 【大得369】
transCnMoney(number){
var CN_MONEY = "";
var CN_UNIT = "仟佰拾亿仟佰拾万仟佰拾元角分";
number = parseFloat(number).toFixed(2).toString();//浏览器默认为整数型,将数字转为2位有效数字的float类型再转为字符串
var dot = number.indexOf('.');//将从小数点开始分开
if(dot >=0){
number = number.substring(0,dot)+number.substr(dot+1,2);
CN_UNIT=CN_UNIT.substr(CN_UNIT.length-number.length);
for (var i = 0; i < number.length; i++){
CN_MONEY += '零壹贰叁肆伍陆柒捌玖'.substr(number.substr(i, 1), 1) + CN_UNIT.substr(i, 1);
}
return CN_MONEY.replace(/零角零分$/, '整').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([亿|万])/g, '$1').replace(/零+元/, '元').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元");
}else{
}
},
边栏推荐
- strncat() strncmp()
- Remember an experience of being cheated by the Internet
- Getting started database days2
- Finding all paths between two points in a directed graph
- fl studio 20.9更新中文版宿主DAW数字音频工作站
- Three network modes of VMware virtual machine
- None and Nan, Nan, Nan
- 视频号加强打击低俗内容:对违背公序良俗的内容必须赶尽杀绝
- Lixia action 2022 Yuanqi digital round table forum will be launched soon
- BGP选路,MPLS
猜你喜欢

Grey correlation analysis (matlab)

(CVPR-2022)BiCnet

strncat() strncmp()

Getting started database Days1

This article will show you what typescript is

Crazy God redis notes 10

D1-h development board - Introduction to Nezha development

ES6 other syntax and extended syntax summary

糖尿病遗传风险检测挑战赛进阶
![Is the height of binary tree [log2n]+1 equal to log2 (n+1)](/img/64/381376190218d5b2cdfd8b1197e8f6.png)
Is the height of binary tree [log2n]+1 equal to log2 (n+1)
随机推荐
strncat() strncmp()
48: Chapter 5: develop admin management service: 1: create sub project [imooc news dev Service Admin], management service module;
STM32F4查看系统各部分频率
2、 Digital logic functional unit
Contemporary inspirational "women"
1、 Simplification of digital logic
Introduction to mysqlbinlog command (remote pull binlog)
Series of articles | the way to advance the microservice architecture in the cloud native era - best practices of microservice splitting
System memory introduction and memory management
The Minesweeper game
What is the difference between go run, go build and go install
Internet协议栈 TCP/IP模型 物理层、链路层、网络层、传输层、应用层的作用
(CVPR-2022)BiCnet
Mongodb - Introduction to the usage of logical operators not, and, or, nor in query statements
The font of Siyuan notes is thinner and lighter than that in other editors (atom, VSC, sublime)
Ways to improve the utilization of openeuler resources 01: Introduction
Redis管道技术/分区
Interface test
Use of pairwise
Getting started database days2