当前位置:网站首页>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))
边栏推荐
- 【无标题】
- Hotel public broadcasting background music - Design of hotel IP network broadcasting system based on Internet +
- Make your own dataset
- 谷歌 | 蛋白序列的深度嵌入和比对
- Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn
- 2022.7.2day594
- Introduction to deep learning (II) -- univariate linear regression
- 大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南
- Basic introduction of redis and explanation of eight types and transactions
- 酒店公共广播背景音乐-基于互联网+的酒店IP网络广播系统设计
猜你喜欢

3dslam with 16 line lidar and octomap

Differences among bio, NiO and AIO

"C and pointer" - Chapter 13 advanced pointer int * (* (* (*f) () [6]) ()

谷歌 | 蛋白序列的深度嵌入和比对

Communication - how to be a good listener?

Deep embedding and alignment of Google | protein sequences

Map的扩容机制

求质数的方法

【实战项目】自主web服务器

Deploy crawl detection network using tensorrt (I)
随机推荐
Brief introduction of realsense d435i imaging principle
Sophomore dilemma (resumption)
ES 2022 正式发布!有哪些新特性?
Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
(subplots usage) Matplotlib how to draw multiple subgraphs (axis field)
Obtenir et surveiller les journaux du serveur distant
Robot capture experiment demonstration video
Interview question -- output the same characters in two character arrays
期末复习(day3)
Making coco datasets
es7创建索引容易犯的错误
今天很多 CTO 都是被幹掉的,因為他沒有成就業務
"C and pointer" - Chapter 13 advanced pointer int * (* (* (*f) () [6]) ()
联想R7000显卡的拆卸与安装
Deploy crawl detection network using tensorrt (I)
Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN
Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in
Why is go language particularly popular in China
Covering Safari and edge, almost all mainstream browsers have realized webgl 2.0 support
Introduction to deep learning (II) -- univariate linear regression