当前位置:网站首页>Niuke JS separator
Niuke JS separator
2022-07-03 05:35:00 【TA_ WORLD】
Cattle from JS Separator ( Digit thousand separator )
describe
Please complete it JavaScript Code , The thousand separator string of the parameter number is required to be returned .
Example
Input :_comma(12300)
Output :‘12,300’
Input :_comma(-123456789)
Output :-123,456,789
function _comma(number) {
let resArr = []
let count = 0
// Whether the mark is negative
let flag = false
// Dealing with negative numbers
if(number < 0){
number = Math.abs(number)
flag = true
}
// Deal with numbers after the decimal point
const parts = number.toString().split('.')
number = parts[0]
const afterPoint = '.' + parts[1] || ''
while(number >= 1){
const current = number % 10
resArr.unshift(String(current))
count++
number = Math.floor(number / 10)
if(count % 3 === 0 && number >= 1){
resArr.unshift(',')
}
}
console.log(resArr,afterPoint)
return (flag ? '-' : '') + resArr.join('') + afterPoint
}
console.log(_comma(1546546.4688))
边栏推荐
- Bluebridge cup real topic 2020 palindrome date simulation construction provincial competition
- 中职网络子网划分例题解析
- 2022.DAY592
- The request database reported an error: "could not extract resultset; SQL [n/a]; needed exception is org.hibernate.exception.sqlgram"
- Altaro o365 total backup subscription plan
- Why is go language particularly popular in China
- Pytorch through load_ state_ Dict load weight
- How to set up altaro offsite server for replication
- Covering Safari and edge, almost all mainstream browsers have realized webgl 2.0 support
- 期末复习DAY8
猜你喜欢
6.23星期四库作业
Intégration profonde et alignement des séquences de protéines Google
3dslam with 16 line lidar and octomap
Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN
Altaro o365 total backup subscription plan
Webrtc M96 release notes (SDP abolishes Plan B and supports opus red redundant coding)
Go practice - gorilla / handlers used by gorilla web Toolkit
一起上水硕系列】Day 9
Sophomore dilemma (resumption)
Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
随机推荐
Disassembly and installation of Lenovo r7000 graphics card
Simpleitk learning notes
NG Textarea-auto-resize
Yolov5 network structure + code + application details | CSDN creation punch in
The request database reported an error: "could not extract resultset; SQL [n/a]; needed exception is org.hibernate.exception.sqlgram"
How do I migrate my altaro VM backup configuration to another machine?
Go practice -- gorilla/rpc (gorilla/rpc/json) used by gorilla web Toolkit
Final review (day3)
【一起上水硕系列】Day 7 内容+Day8
Apache+PHP+MySQL环境搭建超详细!!!
Final review (Day7)
Final review (Day5)
PHP笔记超详细!!!
期末复习(Day5)
Win10 install pytullet and test
Final review (Day6)
一起上水硕系列】Day 9
mapbox尝鲜值之云图动画
How to install and configure altaro VM backup for VMware vSphere
BTC-密码学原理