From a62715878b28c5be8c5633fd14e640317bf8267d Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期五, 03 一月 2025 13:52:13 +0800 Subject: [PATCH] 手机端下载问题 --- src/utils/util.ts | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-) diff --git a/src/utils/util.ts b/src/utils/util.ts index 83c85ba..d92279e 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -547,6 +547,7 @@ const endDate = new Date(); const startDate = new Date(); startDate.setTime(startDate.getTime() - 3600 * 1000 * 24 * dates); + endDate.setHours(23,59,59,59) startDate.setHours(0, 0, 0, 0); return [startDate, endDate]; }; @@ -620,13 +621,30 @@ export const toPercent = (num: number, havePercentSymbol = true, decimalPlaces = 1, defaultValue = '-') => { if (num == null) return `${defaultValue} %`; - let percent = Number(num * 100).toFixed(decimalPlaces); + const factor = Math.pow(10, decimalPlaces); + + let percent = Math.round(Number(num) * 100 * factor) / factor + ''; if (havePercentSymbol) { percent += '%'; } return percent; }; + + +/** + * 淇濈暀鎸囧畾绮惧害灏忔暟浣嶏紝涓斾笉琛ラ浂 + * @param num + * @param precision + * @returns + */ +export const toMyFixed = (num, precision) => { + if (num == null) return ''; + if (!precision) return num + ''; + const factor = Math.pow(10, precision); + return Math.round(Number(num) * factor) / factor + ''; +}; + /** * * @param {*} func 闃叉姈鍑芥暟 -- Gitblit v1.9.3