formatThousands method

String formatThousands({
  1. String symbol = ',',
  2. int? fractionDigits,
  3. bool round = true,
})

Number thousandths handling in string format.

symbol Symbolic form of thousandths.

fractionDigits Keep the number of fractional parts.

round True turns rounding on; False turns rounding off.

Implementation

String formatThousands({
  String symbol = ',',
  int? fractionDigits,
  bool round = true,
}) {
  String result = replaceAll(' ', '');
  final Map<String, String> map = IDKitThousands.handleSignBit(result);
  late String sign = map['sign']!;
  result = map['value']!;
  result = IDKitThousands.handleThousands(
    result,
    symbol,
    fractionDigits,
    round,
  );
  return sign.isEmpty ? result : '$sign$result';
}