Flutter & Dart: Displaying Large Numbers with Digit Grouping

Last updated on November 7, 2021 A Goodman Loading... Post a comment

Displaying large numbers with commas as thousands separators will increase the readability. This short article will show you how to do so in Dart (and Flutter as well) with the help of the NumberFormat class from the intl package (published by the Dart team).

Adding intl to your project by executing the following command:

dart pub add intl

Example:

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

void main() {
  const int a = 1234533323434343433;
  const int b = 1000000;
  const int c = 45030325454;

  NumberFormat myFormat = NumberFormat.decimalPattern('en_us');
  debugPrint(myFormat.format(a));
  debugPrint(myFormat.format(b));
  debugPrint(myFormat.format(c));
}

Output:

1,234,533,323,434,343,433
1,000,000
45,030,325,454

Further reading:

You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

You May Also Like