formatAmount method

String formatAmount({
  1. String? separator,
  2. String? decimal,
})

Implementation

String formatAmount({ String? separator, String? decimal }){
  String priceInText = "";
  separator ??= ' ';
  decimal ??= ',';
  int counter = 0;

  dynamic splittedNumber = split('.');

  for(int i = (splittedNumber[0].length - 1);  i >= 0; i--){
      counter++;
      String str = splittedNumber[0][i];
      if((counter % 3) != 0 && i !=0){
        priceInText = "$str$priceInText";
      }else if(i == 0 ){
        priceInText = "$str$priceInText";

      }else{
        priceInText = "$separator$str$priceInText";
      }
  }
  return '${priceInText.trim()}$decimal${splittedNumber[1]}';
}