当前位置:网站首页>(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));
},
边栏推荐
- consul 配置相关
- 2022 simulated examination platform operation of high voltage electrician work license question bank
- [essence] explain in detail the memory management mechanism in QT
- QT realizes multi screen and multi-resolution adaptation
- torch.logical_and()方法
- Knowledge points of 2022 system integration project management engineer examination: project cost management
- 2024. 考试的最大困扰度-滑动窗口
- 128. 最长连续序列-哈希表
- API handling Android security distance
- Gets the number of occurrences of a character in a string
猜你喜欢

Analysis of 43 cases of MATLAB neural network: Chapter 8 prediction of GRNN Network - Freight Volume Prediction Based on generalized regression neural network
![Sword finger offer:[day 8 dynamic planning (simple)] --- > frog jumping on steps](/img/0a/65bc44850e52204af278e50a8f86eb.jpg)
Sword finger offer:[day 8 dynamic planning (simple)] --- > frog jumping on steps

Jupyter notebook sets the default browser to open with an error syntaxerror: (Unicode error) 'UTF-8' codec can't decode byte 0xd4

EIP-1559

Load the source code of 2D 3D virtual anchor in the web page (1: project introduction and source code)

MySQL learning record - II. MySQL create table command

Unittest测试框架

第三章 寄存器 (内存访问)

【无标题】Task3 多路召回

Xshell startup encountered "unable to continue code execution because mfc110.dll cannot be found"
随机推荐
Binlog in mysql:
ISCSI详解(五)——ISCSI客户端配置实战
Dynamically create and submit forms
Background location case 1
【sklearn学习】LightGBM
Sword finger offer II 016 Longest substring without repeating characters - sliding window
128. longest continuous sequence hash table
Regular verification user name
Loading circling effect during loading
The database doesn't know what went wrong
MFS explanation (IV) -- MFS management server installation and configuration
(node:22344) [DEP0123] DeprecationWarning: Setting the TLS ServerName to an IP address is not permit
Background location case II
2024. maximum difficulty of the exam - sliding window
ERROR 1630 (42000): FUNCTION a.avg does not exist. Check the ‘Function Name Parsing and Resolution‘
Chapter VI - procedures with multiple segments
Chapter 7 - more flexible location of memory addresses
最少换乘次数
解决当打开Unity时 提示项目已经打开,而自己之前并没有打开过(可能之前异常关闭)的问题
QT realizes multi screen and multi-resolution adaptation