当前位置:网站首页>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;
}
边栏推荐
- Sqldeveloper tools quick start
- Pdf translation, which translation company in Beijing is good
- selenium 代码存放
- Summary and analysis of image level weakly supervised image semantic segmentation
- Mysql-03 database operation
- Lingo软件的使用
- AMB | 迈向可持续农业:根际微生物工程
- One stop monitoring of the software and hardware infrastructure of the whole university, and Suzhou University replaces PostgreSQL with time series database
- 过滤器和拦截器的区别
- 键盘快捷键操作电脑(自己遇到不会的)
猜你喜欢

RPN:Region Proposal Networks (区域候选网络)

10 schemes to ensure interface data security
Network pictures are transferred locally, causing the kernel to exit

GOM login configuration free version generate graphic tutorial

C# 常用功能整合

VP视频结构化框架

Stacked noise reducing auto encoder (sdae)

嵌入式开发:调试嵌入式软件的技巧

AMB | towards sustainable agriculture: rhizosphere microbial engineering
![[2022 national game simulation] Bai Loujian - Sam, rollback Mo team, second offline](/img/e1/0574dd4eb311e79afdb1d071f59c4d.png)
[2022 national game simulation] Bai Loujian - Sam, rollback Mo team, second offline
随机推荐
[ostep] 04 virtualized CPU - process scheduling strategy
Create root permission virtual environment
Summary of target tracking related knowledge
请问数据库规范的文档吗 参考一下?
Network pictures are transferred locally, causing the kernel to exit
Learning basic knowledge of Android security
基于CAS的SSO单点登录环境搭建
PyTorch中 torch.nn与torch.nn.functional的区别
[1.2. return and risk of investment]
How to evaluate the test quality?
Flask send_ Absolute path traversal caused by file function
《MySQL高级篇》五、InnoDB数据存储结构
『SignalR』.NET使用 SignalR 进行实时通信初体验
TDengine 助力西门子轻量级数字化解决方案 SIMICAS 简化数据处理流程
Matlab solution of [analysis of variance]
maya将模型导入到unity
【使用工具条绘图】
Whaledi message queue stability improvement practice
Use cpolar to build a commercial website (apply for website security certificate)
Classic line style login interface