当前位置:网站首页>(JS) three digits are separated by commas, and two decimal places are reserved (or rounded)
(JS) three digits are separated by commas, and two decimal places are reserved (or rounded)
2022-06-12 09:01:00 【Gusts of warm air】
The three are separated by commas , Keep two decimal places
//1, Encapsulation method
handleNum(num){
//(1) Keep two decimal places
//var dot = String(num).indexOf(".");
//if(dot != -1){
//var dotCnt = String(num).substring(dot+1,num.length);
//if(dotCnt.length > 2) num = num.toFixed(2);
//}
//(2) Round to the nearest whole number
num = Math.round(num)
// Three digit separation
return String(num).replace(/\d+/, function(n) {
return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
});
},
//2, call , Pass in the number type
onLoad() {
console.log(this.handleNum(1234.0285678));
},
边栏推荐
- [data storage] storage of floating point data in memory
- Judge whether the object is empty
- Background position - mixed units
- Popular understanding of time domain sampling and frequency domain continuation
- API handling Android security distance
- 《MATLAB 神经网络43个案例分析》:第8章 GRNN网络的预测----基于广义回归神经网络的货运量预测
- Building a cluster: and replacing with error
- 【sklearn学习】LightGBM
- 目标识别、检测和 6D 姿态估算源码与方案(最先进的方法和数据集)
- 网页中加载二次元3D虚拟主播源码(1:项目介绍和源码)
猜你喜欢
![[character set 7] what are the wide character codes and multi byte codes of Chinese characters](/img/8c/6d375d90234e6094b6930c2cefefa1.png)
[character set 7] what are the wide character codes and multi byte codes of Chinese characters

Binlog in mysql:

域名映射到指定IP

EIP-1559
![[compilation principle] understand BNF](/img/64/9a0e7507606781336fdc44116ba423.jpg)
[compilation principle] understand BNF

Machine learning notes - circular neural network memo list

Background location case 1

2022 low voltage electrician retraining question bank and online simulation examination

【无标题】Task3 多路召回
![[character set 8] char8_ t、char16_ t、char32_ t、wchar、char](/img/ef/e57fb345b36c84d3585fca0568b0ee.png)
[character set 8] char8_ t、char16_ t、char32_ t、wchar、char
随机推荐
(node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit
EIP-1559
128. longest continuous sequence hash table
Use NVM to dynamically adjust the nodejs version to solve the problem that the project cannot be run and packaged because the node version is too high or too low
(十二)交互组件Selectable
128. Plus longue séquence continue - table de hachage
Source code and scheme for target recognition, detection and 6D attitude estimation (the most advanced method and data set)
JS to refresh the page after loading
Offer:[day 8 dynamic planning (simple)] --- > maximum profit of stock
day5-x
Background location case 1
node示例后台搭建
Summary of common character sets
分库分表会带来读扩散问题?怎么解决?
2024. maximum difficulty of the exam - sliding window
top命令含义
[sklearn] lightgbm
Judge whether the object is empty
[compilation principle] understand BNF
Jenkins Pipeline 语法