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 (officially published by the Dart team).
Adding intl to your project by executing the following command:
flutter 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:
- Using Static Methods in Dart and Flutter
- How to Subtract two Dates in Flutter & Dart
- Dart: Converting a List to a Map and Vice Versa
- Dart: Checking whether a Map is empty
- Using Cascade Notation in Dart and Flutter
- Flutter: Drawing an N-Pointed Star with CustomClipper
You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.