6 C
New York
Monday, December 11, 2023

Flutter & Dart: Displaying Large Numbers with Digit Grouping

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:Advertisements

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:

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

Advertisements

Related Articles

Latest Articles