|
|
@@ -248,4 +248,23 @@ tool.formatMillisecondsToTime = (milliseconds) =>{
|
|
|
|
|
|
return `${formatHours}:${formatMinutes}:${formatSeconds}`;
|
|
|
}
|
|
|
+// 添加上面的 formatValue 函数
|
|
|
+tool.formatValue = (value) => {
|
|
|
+ if (value === 0 || value === '0') {
|
|
|
+ return '0'+'%';
|
|
|
+ }
|
|
|
+
|
|
|
+ const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
|
+ const result = num * 100;
|
|
|
+
|
|
|
+ // 转为带两位小数的字符串,然后去除末尾不必要的0
|
|
|
+ let formatted = result.toFixed(2);
|
|
|
+ if (formatted.endsWith('.00')) {
|
|
|
+ formatted = formatted.slice(0, -3); // 去掉 .00
|
|
|
+ } else if (formatted.endsWith('0')) {
|
|
|
+ formatted = formatted.slice(0, -1); // 去掉末尾的0
|
|
|
+ }
|
|
|
+
|
|
|
+ return formatted + '%';
|
|
|
+}
|
|
|
export default tool
|