mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
优化魔力积分显示为万、亿
This commit is contained in:
33
static/js/utils.js
Normal file
33
static/js/utils.js
Normal file
@@ -0,0 +1,33 @@
|
||||
function renderSize(value) {
|
||||
if (null == value || value == '') {
|
||||
return 0;
|
||||
}
|
||||
var unitArr = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
var index = 0;
|
||||
var srcsize = parseFloat(value);
|
||||
index = Math.floor(Math.log(srcsize) / Math.log(1024));
|
||||
var size = srcsize / Math.pow(1024, index);
|
||||
size = size.toFixed(2);//保留的小数位数
|
||||
return size + ' ' + unitArr[index];
|
||||
}
|
||||
|
||||
function shuffle() {
|
||||
return Math.random() > 0.5 ? -1 : 1;
|
||||
}
|
||||
|
||||
function numberFormat(value) {
|
||||
let param = {}
|
||||
let k = 10000
|
||||
let sizes = ['', 'W', 'E']
|
||||
let i
|
||||
if (value < k) {
|
||||
param.value = value
|
||||
param.unit = ''
|
||||
} else {
|
||||
i = Math.floor(Math.log(value) / Math.log(k));
|
||||
param.value = ((value / Math.pow(k, i))).toFixed(2);
|
||||
param.unit = sizes[i];
|
||||
}
|
||||
console.log(param)
|
||||
return `${param.value}${param.unit}`;
|
||||
}
|
||||
Reference in New Issue
Block a user