当前位置:网站首页>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))
边栏推荐
- 期末复习(Day2)
- Redis 击穿穿透雪崩
- 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
- Introduction to deep learning - definition Introduction (I)
- 2022.7.2day594
- Go practice - gorilla / handlers used by gorilla web Toolkit
- Talk about how to use p6spy for SQL monitoring
- mapbox尝鲜值之云图动画
- ES 2022 正式发布!有哪些新特性?
- Common interview questions of microservice
猜你喜欢

Altaro virtual machine replication failed: "unsupported file type vmgs"

@Autowired 导致空指针报错 解决方式

(完美解决)matplotlib图例(legend)如何自由设置其位置

XML Configuration File

Deploy crawl detection network using tensorrt (I)

Hotel public broadcasting background music - Design of hotel IP network broadcasting system based on Internet +

BIO、NIO、AIO区别

Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)

Brief introduction of realsense d435i imaging principle

How do I migrate my altaro VM backup configuration to another machine?
随机推荐
About debugging the assignment of pagenum and PageSize of the formal parameter pageweb < T > (i.e. page encapsulation generic) in the controller
Make your own dataset
redis 无法远程连接问题。
Go practice -- use JWT (JSON web token) in golang
2022.6.30DAY591
Jetson AGX Orin 平台移植ar0233-gw5200-max9295相机驱动
(subplots用法)matplotlib如何绘制多个子图(轴域)
Deploy crawl detection network using tensorrt (I)
Latest version of source insight
Azure file synchronization of altaro: the end of traditional file servers?
Go practice -- generate and read QR codes in golang (skip2 / go QRcode and boombuilder / barcode)
小学校园IP网络广播-基于校园局域网的小学IP数字广播系统设计
2022.7.2 simulation match
Pan details of deep learning
大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南
【无标题】
@Autowired 导致空指针报错 解决方式
Go practice -- use redis in golang (redis and go redis / redis)
Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
College campus IP network broadcasting - manufacturer's design guide for college campus IP broadcasting scheme based on campus LAN