feat(mining-app): 提升价格显示小数精度

- K线详情弹窗(开/高/低/收):小数位数增加5位
  - 价格≥1: 4位 → 9位
  - 价格0.0001~1: 6位 → 11位
  - 超小价格有效数字: 4位 → 9位
- 兑换页面"当前积分股价值":小数位数增加2位
  - formatPriceFull 新增 extraDecimals 可选参数,支持按需增加精度
  - 调用时传入 extraDecimals: 2
- 资产页面"总资产估值":小数位数从4位增加到6位
  - formatAmount(4位) → formatDecimal(6位)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-06 07:46:28 -08:00
parent cd1d16fc7f
commit 254796b08d
4 changed files with 11 additions and 10 deletions

View File

@ -71,12 +71,13 @@ String formatPrice(String? value) {
}
/// formatPrice 使 0.0{n} 0
String formatPriceFull(String? value) {
/// [extraDecimals]
String formatPriceFull(String? value, {int extraDecimals = 0}) {
if (value == null || value.isEmpty) return '0';
try {
final decimal = Decimal.parse(value);
if (decimal >= Decimal.one) return decimal.toStringAsFixed(4);
if (decimal >= Decimal.parse('0.0001')) return decimal.toStringAsFixed(6);
if (decimal >= Decimal.one) return decimal.toStringAsFixed(4 + extraDecimals);
if (decimal >= Decimal.parse('0.0001')) return decimal.toStringAsFixed(6 + extraDecimals);
if (decimal <= Decimal.zero) return '0';
final str = decimal.toStringAsFixed(18);
final dotIndex = str.indexOf('.');
@ -88,8 +89,8 @@ String formatPriceFull(String? value) {
break;
}
}
// + 7
final sigEnd = dotIndex + 1 + zeroCount + 7;
// + 7 + extraDecimals
final sigEnd = dotIndex + 1 + zeroCount + 7 + extraDecimals;
final end = sigEnd > str.length ? str.length : sigEnd;
return str.substring(0, end);
} catch (e) {

View File

@ -366,7 +366,7 @@ class _AssetPageState extends ConsumerState<AssetPage> {
const SizedBox(height: 8),
// -
AmountText(
amount: displayValue != null ? formatAmount(displayValue) : null,
amount: displayValue != null ? formatDecimal(displayValue, 6) : null,
isLoading: isLoading,
suffix: ' 积分值',
style: const TextStyle(

View File

@ -214,7 +214,7 @@ class _TradingPageState extends ConsumerState<TradingPage> {
textBaseline: TextBaseline.alphabetic,
children: [
AmountText(
amount: priceInfo != null ? formatPriceFull(price) : null,
amount: priceInfo != null ? formatPriceFull(price, extraDecimals: 2) : null,
isLoading: isLoading,
style: const TextStyle(
fontSize: 30,

View File

@ -728,8 +728,8 @@ class _KlineChartWidgetState extends State<KlineChartWidget> {
}
String _formatPrice(double price) {
if (price >= 1) return price.toStringAsFixed(4);
if (price >= 0.0001) return price.toStringAsFixed(6);
if (price >= 1) return price.toStringAsFixed(9);
if (price >= 0.0001) return price.toStringAsFixed(11);
if (price <= 0) return '0';
// 0.00000980 0.0{5}980
final str = price.toStringAsFixed(18);
@ -743,7 +743,7 @@ class _KlineChartWidgetState extends State<KlineChartWidget> {
}
}
final sigStart = dotIndex + 1 + zeroCount;
final sigEnd = math.min(sigStart + 4, str.length);
final sigEnd = math.min(sigStart + 9, str.length);
final significant = str.substring(sigStart, sigEnd);
return '0.0{$zeroCount}$significant';
}