fix: 建议仓位按量级自适应小数位(修复 BTC 等高价币显示为0)+ 通用化单位
This commit is contained in:
14
index.html
14
index.html
@@ -134,7 +134,7 @@
|
||||
<div class="wrap">
|
||||
<header>
|
||||
<div class="eyebrow">Position Sizer · 逐仓</div>
|
||||
<h1>合约仓位计算器 <span class="sym">/ DOGE-USDT</span></h1>
|
||||
<h1>合约仓位计算器 <span class="sym">/ 通用合约</span></h1>
|
||||
<div class="sub">先定亏损上限,再反推仓位。杠杆只决定爆仓距离,不决定你亏多少。</div>
|
||||
</header>
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
<span class="risk" id="slShow"></span>
|
||||
</div>
|
||||
<div class="big">
|
||||
<div class="lbl">建议仓位 · DOGE 数量</div>
|
||||
<div class="lbl">建议仓位 · 合约数量</div>
|
||||
<div class="val" id="qty">—</div>
|
||||
</div>
|
||||
<div class="pair">
|
||||
@@ -291,6 +291,12 @@
|
||||
|
||||
const fmtN=(n,d=2)=>isFinite(n)?n.toLocaleString('en-US',{minimumFractionDigits:d,maximumFractionDigits:d}):'—';
|
||||
const fmtP=n=>isFinite(n)?n.toLocaleString('en-US',{minimumFractionDigits:5,maximumFractionDigits:5}):'—';
|
||||
// 仓位数量:按量级自适应小数位(大币种如 BTC 量很小,小币种如 DOGE 量上千)
|
||||
const fmtQty=n=>{
|
||||
if(!isFinite(n)) return '—';
|
||||
const d = n>=1000?0 : n>=100?1 : n>=1?2 : n>=0.01?4 : 6;
|
||||
return n.toLocaleString('en-US',{minimumFractionDigits:0,maximumFractionDigits:d});
|
||||
};
|
||||
|
||||
function calc(){
|
||||
const bal=+$('balance').value, riskPct=+$('riskPct').value, entry=+$('entry').value;
|
||||
@@ -313,10 +319,10 @@
|
||||
const dist=Math.abs(entry-slPrice);
|
||||
if(!(dist>0)){ clearOut(); return; }
|
||||
|
||||
const qty = risk/dist; // DOGE 数量
|
||||
const qty = risk/dist; // 合约数量
|
||||
const notional = qty*entry; // 名义价值 U
|
||||
|
||||
$('qty').innerHTML = fmtN(qty,0)+' <span class="u">DOGE</span>';
|
||||
$('qty').innerHTML = fmtQty(qty)+' <span class="u">币</span>';
|
||||
$('notional').innerHTML = fmtN(notional)+' <span class="u">U</span>';
|
||||
$('slPriceShow').textContent = fmtP(slPrice);
|
||||
$('slShow').textContent = '止损 '+fmtN(slPctVal)+'%';
|
||||
|
||||
Reference in New Issue
Block a user