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:
parent
cd1d16fc7f
commit
254796b08d
|
|
@ -71,12 +71,13 @@ String formatPrice(String? value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 与 formatPrice 相同逻辑,但不使用 0.0{n} 缩写,直接展示完整的0
|
/// 与 formatPrice 相同逻辑,但不使用 0.0{n} 缩写,直接展示完整的0
|
||||||
String formatPriceFull(String? value) {
|
/// [extraDecimals] 可额外增加小数位数
|
||||||
|
String formatPriceFull(String? value, {int extraDecimals = 0}) {
|
||||||
if (value == null || value.isEmpty) return '0';
|
if (value == null || value.isEmpty) return '0';
|
||||||
try {
|
try {
|
||||||
final decimal = Decimal.parse(value);
|
final decimal = Decimal.parse(value);
|
||||||
if (decimal >= Decimal.one) return decimal.toStringAsFixed(4);
|
if (decimal >= Decimal.one) return decimal.toStringAsFixed(4 + extraDecimals);
|
||||||
if (decimal >= Decimal.parse('0.0001')) return decimal.toStringAsFixed(6);
|
if (decimal >= Decimal.parse('0.0001')) return decimal.toStringAsFixed(6 + extraDecimals);
|
||||||
if (decimal <= Decimal.zero) return '0';
|
if (decimal <= Decimal.zero) return '0';
|
||||||
final str = decimal.toStringAsFixed(18);
|
final str = decimal.toStringAsFixed(18);
|
||||||
final dotIndex = str.indexOf('.');
|
final dotIndex = str.indexOf('.');
|
||||||
|
|
@ -88,8 +89,8 @@ String formatPriceFull(String? value) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 截取到前导零 + 7位有效数字
|
// 截取到前导零 + 7位有效数字 + extraDecimals
|
||||||
final sigEnd = dotIndex + 1 + zeroCount + 7;
|
final sigEnd = dotIndex + 1 + zeroCount + 7 + extraDecimals;
|
||||||
final end = sigEnd > str.length ? str.length : sigEnd;
|
final end = sigEnd > str.length ? str.length : sigEnd;
|
||||||
return str.substring(0, end);
|
return str.substring(0, end);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
|
|
@ -366,7 +366,7 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
// 金额 - 实时刷新显示
|
// 金额 - 实时刷新显示
|
||||||
AmountText(
|
AmountText(
|
||||||
amount: displayValue != null ? formatAmount(displayValue) : null,
|
amount: displayValue != null ? formatDecimal(displayValue, 6) : null,
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
suffix: ' 积分值',
|
suffix: ' 积分值',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
||||||
textBaseline: TextBaseline.alphabetic,
|
textBaseline: TextBaseline.alphabetic,
|
||||||
children: [
|
children: [
|
||||||
AmountText(
|
AmountText(
|
||||||
amount: priceInfo != null ? formatPriceFull(price) : null,
|
amount: priceInfo != null ? formatPriceFull(price, extraDecimals: 2) : null,
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 30,
|
fontSize: 30,
|
||||||
|
|
|
||||||
|
|
@ -728,8 +728,8 @@ class _KlineChartWidgetState extends State<KlineChartWidget> {
|
||||||
}
|
}
|
||||||
|
|
||||||
String _formatPrice(double price) {
|
String _formatPrice(double price) {
|
||||||
if (price >= 1) return price.toStringAsFixed(4);
|
if (price >= 1) return price.toStringAsFixed(9);
|
||||||
if (price >= 0.0001) return price.toStringAsFixed(6);
|
if (price >= 0.0001) return price.toStringAsFixed(11);
|
||||||
if (price <= 0) return '0';
|
if (price <= 0) return '0';
|
||||||
// 0.00000980 → 0.0{5}980
|
// 0.00000980 → 0.0{5}980
|
||||||
final str = price.toStringAsFixed(18);
|
final str = price.toStringAsFixed(18);
|
||||||
|
|
@ -743,7 +743,7 @@ class _KlineChartWidgetState extends State<KlineChartWidget> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final sigStart = dotIndex + 1 + zeroCount;
|
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);
|
final significant = str.substring(sigStart, sigEnd);
|
||||||
return '0.0{$zeroCount}$significant';
|
return '0.0{$zeroCount}$significant';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue