四舍五入,保留n位小数
export function round(number, n) {
n = n ? parseInt(n) : 0
if (n <= 0) return Math.round(number)
number = Math.round(number * Math.pow(10, n)) / Math.pow(10, n)
return number
}
数字每千位加逗号
1、toLocaleString()
2、export function toThousands(num) {
return num && num.toString()
.replace(/\d+/, function(s){
return s.replace(/(\d)(?=(\d{3})+$)/g, '$1,')
})
}
随机数
export function random(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}