intComma function

String intComma(
  1. int value

Convert an integer to a string containing commas every three digits. For example, 3000 becomes '3,000' and 45000 becomes '45,000'.


String intComma(int value) {
   // Convert int value to a String one
   String valueToString = '$value';

   // Use RegExp function witch used to match strings or parts of strings
   RegExp reg = new RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))');
   Function mathFunc = (Match match) => '${match[1]},';

   // Store the result in a new String value

   String newValue = valueToString.replaceAllMapped(reg, mathFunc);

   return '$newValue';