111
This commit is contained in:
Binary file not shown.
@@ -107,7 +107,9 @@ class _TradePageState extends State<TradePage>
|
||||
final amount = double.tryParse(_amountController.text) ?? 0;
|
||||
final price = _selectedCoin?.price ?? 0;
|
||||
if (price <= 0 || amount <= 0) return '0';
|
||||
return (amount / price).toStringAsFixed(6);
|
||||
// 向下截斷到4位小數,避免回算超出金額
|
||||
final qty = amount / price;
|
||||
return ((qty * 10000).truncateToDouble() / 10000).toStringAsFixed(4);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -207,7 +209,10 @@ class _TradePageState extends State<TradePage>
|
||||
final max = double.tryParse(_maxAmount) ?? 0;
|
||||
final value = max * pct;
|
||||
// 向下截斷到2位小數,避免四捨五入超出可用餘額
|
||||
_amountController.text = ((value * 100).truncateToDouble() / 100).toStringAsFixed(2);
|
||||
// 向下截斷到2位小數,再減0.01作為安全緩衝,避免精度問題導致餘額不足
|
||||
final truncated = ((value * 100).truncateToDouble() / 100);
|
||||
final safe = truncated > 0.01 ? truncated - 0.01 : truncated;
|
||||
_amountController.text = safe.toStringAsFixed(2);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user