Search code examples
flutterdart

Formatting a number with space instead of commas as thousand separator


Is there a way to display a number like 1000000 as 1 000 000 ? I have tried using NumberFormat

var formatter = NumberFormat("#,###");
return Text("${formatter.format(price.toInt())}"); // 985000 returns 985,000

But i would like to have a space instead of the commas

EDIT

Solved by adding the method replaceAll

var formatter = NumberFormat('#,###');
return Text('${formatter.format(price.toInt())}'.replaceAll(',', ' '));

Thanks again!


Solution

  • var formatter = NumberFormat('#,###');
    return Text('${formatter.format(price.toInt())}'.replaceAll(',', ' '));