Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I round millions in Flutter? Example '29,971,800' to '30,00,000'

Given a value example: 29971800.0 & I format it using NumberFormat.decimalPattern() so I got ‘29,971,800’. The problem is I want to round it to get the value of ‘30,000,000’ instead of ‘29,971,800’ or other example I want to round ‘356,740,000’ to ‘357,000,000’.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Before you format round it using num.round() for example if you want to round to millions

double n = 29971800;
double roundTo = 1000000; //million
print((n/roundTo).round()); //prints 30

you can either multiply it by million and format it or just convert to String and add ',000,000'

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading