You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何用空格替代逗号作为千位分隔符格式化数字

如何将数字转换为空格作为千位分隔符的显示格式

请问是否有方法可以将1000000这类数字显示为1 000 000的格式?我已尝试使用NumberFormat进行格式化:

var formatter = NumberFormat("#,###");
return Text("${formatter.format(price.toInt())}"); // 输入985000时输出为985,000

但目前输出的千位分隔符为逗号,我希望使用空格替代逗号作为千位分隔符。

更新
我已经通过调用replaceAll方法解决了该问题,解决代码如下:

var formatter = NumberFormat('#,###');
return Text('${formatter.format(price.toInt())}'.replaceAll(',', ' '));

感谢大家的帮助!


内容的提问来源于stack exchange,提问作者Aby Bermen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.15 00:54:03