当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

全校软硬件基础设施一站式监控 ,苏州大学以时序数据库替换 PostgreSQL
![[dry goods] data structure and algorithm principle behind MySQL index](/img/80/d5ab431cd5112b1637ee07d5b59afa.png)
[dry goods] data structure and algorithm principle behind MySQL index

Advanced MySQL v. InnoDB data storage structure

TransC知识表示模型

VBA upload pictures

Realize the full link grayscale based on Apache APIs IX through MSE

GOM login configuration free version generate graphic tutorial

Summary of target tracking related knowledge
![[integer programming]](/img/e5/aebc5673903f932030120822e4331b.png)
[integer programming]
![[untitled]](/img/50/7aa01f1d8657700a11cbc26290804a.png)
[untitled]
随机推荐
Network pictures are transferred locally, causing the kernel to exit
Embedded development: skills of debugging embedded software
Realize the full link grayscale based on Apache APIs IX through MSE
Summary and analysis of image level weakly supervised image semantic segmentation
How to evaluate the test quality?
Image-Level 弱监督图像语义分割汇总简析
Devops system of "cloud native" kubesphere pluggable components
保证接口数据安全的10种方案
VP视频结构化框架
Would you please refer to the document of Database specification?
JS wave animation effect menu style
Self encoder AE (autoencoder) program
中部“第一城”,长沙“人才引力”从争先到领先
My creation Anniversary - from the heart
基于CAS的SSO单点登录环境搭建
键盘快捷键操作电脑(自己遇到不会的)
Wechat applet - "do you really understand the use of applet components?
JS analog clock with text label
AMB | towards sustainable agriculture: rhizosphere microbial engineering
WPF common function integration