Can I format a number before it is rendered in

There is a Dart package for formatting numbers, the Dart intl package. To use the package, add the following line to the Dart dependencies: pubspec.yaml file:

  intl: ^0.17.0

Here’s what my dependencies look like with the line:

dependencies:
  flutter:
    sdk: flutter
    intl: ^0.17.0

Click packages get in IntelliJ, or run flutter packages get from the command line.

Make sure your class imports the intl package:

import 'package:intl/intl.dart' as intl;

In your code, you can use NumberFormat class to do the formatting:

  final formatter =  intl.NumberFormat.decimalPattern().format(1234) // formatted number will be: 1,234

Full stateful widget example:

class NumberFormatExample extends StatefulWidget {
  @override
  _NumberFormatExampleState createState() => new _NumberFormatExampleState();
}

class _NumberFormatExampleState extends State<NumberFormatExample> {
  final formatter = intl.NumberFormat.decimalPattern();
  int theValue = 1234;

  @override
  Widget build(BuildContext context) {
    return new Text(formatter.format(theValue));
  }
}
  

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)