extension NumX on num { /// 金额格式化:1234.5 → "1,234.50" String get yuan => '¥${toStringAsFixed(2).replaceAllMapped( RegExp(r'(\d)(?=(\d{3})+\.)'), (m) => '${m[1]},', )}'; /// 百分比:0.75 → "75%" String get percent => '${(this * 100).toStringAsFixed(0)}%'; /// 文件大小:1024 → "1 KB" String get bytesFmt { if (this < 1024) return '$this B'; if (this < 1024 * 1024) return '${(this / 1024).toStringAsFixed(1)} KB'; if (this < 1024 * 1024 * 1024) { return '${(this / 1024 / 1024).toStringAsFixed(1)} MB'; } return '${(this / 1024 / 1024 / 1024).toStringAsFixed(1)} GB'; } } extension NullableNumX on num? { String get orPlaceholder => this?.toString() ?? '-'; }