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

Time:11-11

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'.

CodePudding user response:

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'

  • Related