Reputation: 705
I have built a flutter app in which most of the numerical values can be very big(depending upon user), and there are many widgets, where there are very big numerical values.
So how can I format them like 1,000,000 to 1M or 1 million (same as in youtube)? If I program this for every single widget, the code will become very long. Is there any simple or efficient way like enabling a numberProperty (to true) in the theme data of the app, so that the app can automatically format all the big numbers into their short forms(like M,k), and I do not have to write very big code for every widget.
Upvotes: 3
Views: 1356
Reputation: 220
You should be able to use the NumberFomat Class that is part of the intl package. Specifically look at NumberFormat.compact().
A number format for compact representations, e.g. "1.2M" instead of "1,200,000".
Upvotes: 2