thousandSeparatedFormat property

String get thousandSeparatedFormat

支持千分位格式化 123456789.thousandSeparatedFormat → "123,456,789"

Implementation

String get thousandSeparatedFormat {
  if (this == null) return '0';
  final number = this!;
  final parts = number.toString().split('');
  int len = parts.length;
  int pos = 0;
  String out = '';
  for (int i = len - 1; i >= 0; i--) {
    out = parts[i] + out;
    pos++;
    if (pos % 3 == 0 && i > 0) {
      out = ',$out';
    }
  }
  return out;
}