I am making an app using flutter in which I need to display likes and I wish to display likes correct to 1 place of decimal but 999.9k is being displayed as 1000.0k when I use.toStringAsFixed() method, for some reason it shows a rounded-up value, can someone tell me how to display the number correctly.
Widget result;
if (count == 0) {
result = Text(
'like',
style: TextStyle(color: color),
);
} else if (count! >= 1000000) {
result = Text(
(count / 1000000.0).toStringAsFixed(1) + 'm',
style: TextStyle(color: color),
);
} else
result = Text(
count >= 1000
? (count / pow(10, 3)).toStringAsFixed(1) + 'k'
: text,
style: TextStyle(color: color),
);
print(count!/1000);
return result;
},
toStringAsFixed(0) will not show any decimals. simply calling toStringAsFixed() is rounding your values up.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.