Flutter & Dart: Displaying Large Numbers with Digit Grouping

Updated: August 19, 2022 By: A Goodman One 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 (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.

Subscribe
Notify of
guest
1 Comment
Inline Feedbacks
View all comments
Eddie
Eddie
1 year ago

Hey there quick question, why does NumberFormat.decimalPattern return a maximum of 3 decimal digits and doesn’t allow me to display more.

example myFormat.format(1000.34561)
gives me back 1,000.346

How can I make it so it has an unlimited number of decimals.

Related Articles