flutter number-separator

flutter number-separator


If you need to add separator to your numbers in flutter there are very simple ways to do so, today we will test two of them here.

You just forgot get first digits into group. Use this short one:

[STRING_DATA_HERE].replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]},')

Or you can simply use Intl package as following

import 'package:intl/intl.dart';

var f = NumberFormat("###,###", "en_US");

this prints 1,000,300.

To learn more about this approach read NumberFormat here.

- Last updated 1 year ago


Be the first to leave a comment.

You must login to leave a comment