当前位置:网站首页>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))
边栏推荐
- The request database reported an error: "could not extract resultset; SQL [n/a]; needed exception is org.hibernate.exception.sqlgram"
- Final review Day8
- 2022.7.2 模拟赛
- Explanation of several points needing attention in final (tested by the author)
- 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
- Pessimistic lock and optimistic lock of multithreading
- Source insight automatic installation and licensing
- Introduction to redis and explanation of data types
- Final review (Day7)
- Azure file synchronization of altaro: the end of traditional file servers?
猜你喜欢

(perfect solution) how to set the position of Matplotlib legend freely

Brief introduction of realsense d435i imaging principle

Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in

Webrtc protocol introduction -- an article to understand ice, stun, NAT, turn

配置xml文件的dtd

Make your own dataset

Go practice -- design patterns in golang's singleton

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

Webrtc native M96 version opening trip -- a reading code download and compilation (Ninja GN depot_tools)

kubernetes资源对象介绍及常用命令(五)-(ConfigMap)
随机推荐
Common interview questions of microservice
Pessimistic lock and optimistic lock of multithreading
中职网络子网划分例题解析
Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in
Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
Introduction to deep learning (II) -- univariate linear regression
Deploy crawl detection network using tensorrt (I)
牛客网 JS 分隔符
在PyCharm中配置使用Anaconda环境
redis 无法远程连接问题。
獲取並監控遠程服務器日志
Win10 install pytullet and test
Altaro set grandfather parent child (GFS) archiving
Redis expiration elimination mechanism
How to set up altaro offsite server for replication
Go practice -- generate and read QR codes in golang (skip2 / go QRcode and boombuilder / barcode)
(subplots用法)matplotlib如何绘制多个子图(轴域)
Introduction to redis and explanation of data types
"250000 a year is just the price of cabbage" has become a thing of the past. The annual salary of AI posts has decreased by 8.9%, and the latest salary report has been released
College campus IP network broadcasting - manufacturer's design guide for college campus IP broadcasting scheme based on campus LAN