当前位置:网站首页>js 实现数字转金额价格千分符
js 实现数字转金额价格千分符
2022-07-26 14:35:00 【spring-java】
直接上代码:
function format_with_mod(number) {
let n = number;
let r = '';
let temp = '';
do {
// 求模的值, 用于获取高三位,这里可能有小数
mod = n % 1000;
// 值是不是大于1,是继续的条件
n = n / 1000;
// 高三位
temp = ~~mod;
// 1.填充: n > 1 循环未结束, 就要填充为比如 1 => 001
// 不然temp = ~~mod的时候, 1 001, 就会变成 "11"
// 2.拼接“,”
r = (n >= 1 ? `${temp}`.padStart(3, '0') : temp) + (!!r ? ',' + r : '');
} while (n >= 1);
const strNumber = number + '';
let index = strNumber.indexOf('.');
// 拼接小数部分
if (index >= 0) {
r += strNumber.substring(index);
}
return r;
}
边栏推荐
- VBA upload pictures
- Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process
- 1-to-1 live broadcast source code - 1-to-1 voice chat source code
- AMB | towards sustainable agriculture: rhizosphere microbial engineering
- 目标跟踪相关知识总结
- [dry goods] data structure and algorithm principle behind MySQL index
- 【整数规划】
- Siamrpn++: evolution of deep network connected visual tracking
- SiamFC:用于目标跟踪的全卷积孪生网络
- [ostep] 04 virtualized CPU - process scheduling strategy
猜你喜欢

Summary of target tracking related knowledge

Fill in the questionnaire and receive the prize | we sincerely invite you to fill in the Google play academy activity survey questionnaire
网络图片转本地导致内核退出

Create Yum warehouse inside the enterprise

C# NanUI 相关功能整合

The development of smart home industry pays close attention to edge computing and applet container technology

Pokemon card evolution jsjs special effect

Unity学习笔记–无限地图

Arithmetic operation and logic operation of image in opencv

As the "first city" in Central China, Changsha's "talent attraction" has changed from competition to leadership
随机推荐
当AI邂逅生命健康,华为云为他们搭建三座桥
Instructions for various interfaces of hand-held vibrating wire collector vh03
CAS单点登录
SA Siam: Twin network for real-time target tracking
Transc knowledge representation model
过滤器和拦截器的区别
Unity学习笔记–无限地图
[draw with toolbar]
postman 环境变量设置代码存放
Low power multi-channel wfas1431 wireless data acquisition and transmission instrument operation process description
Learning basic knowledge of Android security
C nanui related function integration
Sqldeveloper tools quick start
C # use shift > > and operation and & to judge whether the two binary numbers have changed
Annotation and reflection
如何评价测试质量?
【1.2.投资的收益和风险】
Use of LINGO software
unity透明通道的小技巧
Multithreading - thread pool