mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-10 00:38:07 +00:00
feat: 更新订单处理逻辑,将价格类型改为字符串以避免精度问题,并添加价格格式化函数
This commit is contained in:
@@ -21,3 +21,14 @@ export function decimalsOf(step: number): number {
|
||||
export function isNearlyZero(value: number, epsilon = 1e-5): boolean {
|
||||
return Math.abs(value) < epsilon;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将价格格式化为指定小数位数的字符串
|
||||
* @param price 原始价格
|
||||
* @param decimals 小数位数
|
||||
* @returns 格式化后的价格字符串
|
||||
*/
|
||||
export function formatPriceToString(price: number, decimals: number): string {
|
||||
if (!Number.isFinite(price)) return "0";
|
||||
return price.toFixed(decimals);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user