fmtNum function

String fmtNum(
  1. int n
)

Formats a large integer (coins, score, price, boss HP…) with a THOUSANDS SEPARATOR matching the CURRENT LANGUAGE: vi → "10.000", en → "10,000", de → "10.000"… Uses NumberFormat (intl) keyed on Get.locale; if the locale is unknown/has no data, falls back to manual grouping with '.' (Vietnamese-style) so it NEVER throws.

Implementation

String fmtNum(int n) {
  try {
    return NumberFormat.decimalPattern(
      Get.locale?.languageCode ?? 'en',
    ).format(n);
  } catch (_) {
    final neg = n < 0;
    final digits = n.abs().toString();
    final buf = StringBuffer();
    for (var i = 0; i < digits.length; i++) {
      if (i > 0 && (digits.length - i) % 3 == 0) buf.write('.');
      buf.write(digits[i]);
    }
    return neg ? '-$buf' : buf.toString();
  }
}