gpt4 book ai didi

flutter - 如果计数值太大,该如何格式化?

转载 作者:行者123 更新时间:2023-12-03 04:42:59 24 4
gpt4 key购买 nike

这是我的buildCountText函数,我在其中传递标签并将count作为参数,我正在使用此函数显示应用程序中的关注者数量,但是如果值很大,我不知道如何格式化计数以千或百万为单位,我不想将整个数字写成百万,我只想写成1M(例如)。但我不知道该如何格式化。

buildCountText(String label, int count) {
return Container(
padding: EdgeInsets.only(top: 5, bottom: 6),
alignment: Alignment.centerLeft,
child: RichText(
text: TextSpan(
//text: label,
style: TextStyle(
fontFamily: "OpenSans", color: Theme.of(context).primaryColor),
children: <TextSpan>[
TextSpan(
text: label,
style: TextStyle(
fontFamily: "OpenSans", fontWeight: FontWeight.w500)),
TextSpan(
text:_isLoading?" ...": ' $count', style: TextStyle(fontWeight: FontWeight.bold)),
],
),
),
);
}

最佳答案

使用数字格式器。 https://pub.dev/documentation/intl/latest/intl/NumberFormat-class.html

var f = NumberFormat.compact();
print(f.format(100000)); //<= prints 100K

关于flutter - 如果计数值太大,该如何格式化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62835046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com