Kinda Code
Home/Dart/Flutter & Dart: Displaying Large Numbers with Digit Grouping

Flutter & Dart: Displaying Large Numbers with Digit Grouping

Last updated: August 19, 2022

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:

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

Related Articles