refactor: 移除刷新代理钱包接口,增加copyRatio精度支持
- 移除刷新代理钱包相关接口和方法 - AccountController: 移除 /refresh-proxy 和 /refresh-all-proxies 接口 - AccountService: 移除 refreshProxyAddress 和 refreshAllProxyAddresses 方法 - 增加 copyRatio 字段精度支持 - CopyTrading: copyRatio 精度从 DECIMAL(10,2) 增加到 DECIMAL(20,8) - CopyTradingTemplate: copyRatio 精度从 DECIMAL(10,2) 增加到 DECIMAL(20,8) - 新增数据库迁移脚本 V18__increase_copy_ratio_precision.sql - 前端工具函数 - 添加 formatNumber 函数用于格式化数字显示 修复的文件: - AccountController.kt - AccountService.kt - CopyTrading.kt - CopyTradingTemplate.kt - frontend/src/utils/index.ts - V18__increase_copy_ratio_precision.sql
This commit is contained in:
@@ -1,3 +1,34 @@
|
||||
/**
|
||||
* 格式化数字,自动去除尾随零
|
||||
* @param value - 数字值(字符串或数字)
|
||||
* @param maxDecimals - 最大小数位数(默认不限制)
|
||||
* @returns 格式化后的字符串,如果值为空或无效则返回 ''
|
||||
* @example
|
||||
* formatNumber(100.00) => "100"
|
||||
* formatNumber(100.50) => "100.5"
|
||||
* formatNumber(100.55) => "100.55"
|
||||
*/
|
||||
export const formatNumber = (value: string | number | undefined | null, maxDecimals?: number): string => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return ''
|
||||
}
|
||||
|
||||
const num = typeof value === 'string' ? parseFloat(value) : value
|
||||
if (isNaN(num)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
// 如果有最大小数位数限制,先截断
|
||||
if (maxDecimals !== undefined) {
|
||||
const multiplier = Math.pow(10, maxDecimals)
|
||||
const truncated = Math.floor(num * multiplier) / multiplier
|
||||
return truncated.toFixed(maxDecimals).replace(/\.?0+$/, '')
|
||||
}
|
||||
|
||||
// 直接转换为字符串,然后去除尾随零
|
||||
return num.toString().replace(/\.?0+$/, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化 USDC 金额
|
||||
* 最多显示 4 位小数,自动去除尾随零(截断,不四舍五入)
|
||||
|
||||
Reference in New Issue
Block a user