Search code examples
flutterdartformatnumbersdart-pub

How to format numbers as thousands separators in Dart


I have to format numbers as thousands separators in dart. I have numbers like:

16987

13876

456786

and I want to format them as :

16,987

13,876 

4,56,786

Solution

  • You can use NumberFormat passing a custom format in ICU formatting pattern, take a look in NumberFormat.

    import 'package:intl/intl.dart';
    
    void main() {
      var formatter = NumberFormat('#,##,000');
      print(formatter.format(16987));
      print(formatter.format(13876));
      print(formatter.format(456786));
    }
    

    Output

    16,987
    13,876
    4,56,786