formatInt function

String? formatInt(
  1. int? number, {
  2. String? def,
  3. int scale = 1,
  4. bool fixZero = false,
  5. int decimalLength = 2,
})

Implementation

String? formatInt(
  int? number, {
  String? def,
  int scale = 1,
  bool fixZero = false,
  int decimalLength = 2,
}) {
  if (number == null) return def;
  var temp = (Decimal.fromInt(number) / Decimal.fromInt(scale))
      .toStringAsFixed(decimalLength);

  if (fixZero) {
    while (temp.contains('.') && (temp.endsWith('0') || temp.endsWith('.'))) {
      temp = temp.substring(0, temp.length - 1);
    }
  }
  return temp;
}