Trim trailing zeros in calculator market info display.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -42,6 +42,16 @@
|
||||
return String(n);
|
||||
}
|
||||
|
||||
/** 去掉尾部多余 0,用于乘数/精度展示 */
|
||||
function fmtTrim(v, maxDigits) {
|
||||
if (v == null || v === "") return "—";
|
||||
const n = Number(v);
|
||||
if (!Number.isFinite(n)) return esc(v);
|
||||
let s = maxDigits != null ? n.toFixed(maxDigits) : String(n);
|
||||
if (s.includes(".")) s = s.replace(/\.?0+$/, "");
|
||||
return s;
|
||||
}
|
||||
|
||||
function fmtU(v) {
|
||||
if (v == null || v === "") return "—";
|
||||
const n = Number(v);
|
||||
@@ -72,12 +82,12 @@
|
||||
const parts = [
|
||||
inst + "<strong>" + esc(market.display_symbol || market.base || "") + "</strong> 永续",
|
||||
"合约 " + esc(market.exchange_symbol || ""),
|
||||
"乘数 " + fmt(market.contract_size, 8),
|
||||
"价格精度 " + fmt(market.price_tick != null ? market.price_tick : Math.pow(10, -(market.price_decimals || 0))),
|
||||
"张数精度 " + fmt(Math.pow(10, -(market.amount_decimals || 0))),
|
||||
"乘数 " + fmtTrim(market.contract_size, 8),
|
||||
"价格精度 " + fmtTrim(market.price_tick != null ? market.price_tick : Math.pow(10, -(market.price_decimals || 0))),
|
||||
"张数精度 " + fmtTrim(Math.pow(10, -(market.amount_decimals || 0))),
|
||||
];
|
||||
if (market.min_amount != null) {
|
||||
parts.push("最小张数 " + fmt(market.min_amount, market.amount_decimals));
|
||||
parts.push("最小张数 " + fmtTrim(market.min_amount, market.amount_decimals));
|
||||
}
|
||||
return parts.join(" · ");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user