humanizeIntInd function

String humanizeIntInd(
  1. int n
)

Function that converts large numbers to humanized form
Returns same if number < 1000
Else Returns rounded number with appropriate suffix in Indian numbering system (Thousand, Lakhs and Crores)
Eg:

234 -> 234
1000 -> 1K
1234 -> 1.2K
12340 -> 12K
1234000 -> 12L
12340000 -> 1.2Cr ....

Implementation

String humanizeIntInd(int n) {
  // < 1000
  if (n < 1000) return n.toString();

  // 1,000s
  if (n < 10000) {
    final s = (n / 1000).toStringAsFixed(1);
    if (s[s.length - 1] == '0') {
      return s.substring(0, s.length - 2) + "K";
    }
    return s + "K";
  }
  if (n < 100000) {
    return (n / 1000).toStringAsFixed(0) + "K";
  }

  // 1,00,000s
  if (n < 1000000) {
    final s = (n / 100000).toStringAsFixed(1);
    if (s[s.length - 1] == '0') {
      return s.substring(0, s.length - 2) + "L";
    }
    return s + "L";
  }
  if (n < 10000000) {
    return (n / 100000).toStringAsFixed(0) + "L";
  }

  // 1,00,00,000s
  if (n < 100000000) {
    final s = (n / 10000000).toStringAsFixed(1);
    if (s[s.length - 1] == '0') {
      return s.substring(0, s.length - 2) + "Cr";
    }
    return s + "Cr";
  }
  if (n < 1000000000) {
    return (n / 10000000).toStringAsFixed(0) + "Cr";
  }

  // >= 100,00,00,000s

  return (n / 10000000).toStringAsFixed(0) + "Cr";
}