mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-21 22:48:13 +00:00
19 lines
540 B
JavaScript
19 lines
540 B
JavaScript
let Format = {
|
|
int: function (d) {
|
|
return parseInt(d);
|
|
},
|
|
comma: function (num, fix = 0) {
|
|
num = parseFloat((num * 1).toFixed(fix));
|
|
let [integer, decimal] = String.prototype.split.call(num, '.');
|
|
integer = integer.replace(/\d(?=(\d{3})+$)/g, '$&,'); // 正则先行断言
|
|
return `${integer}${decimal ? '.' + decimal : ''}`;
|
|
},
|
|
pct: function (num, fix = 1) {
|
|
return (num * 1).toFixed(fix) + "%";
|
|
},
|
|
percent: function (num, fix = 1) {
|
|
return Format.pct(num * 100, fix);
|
|
}
|
|
}
|
|
|
|
export default Format; |