number_format_util.dart 506 B

1234567891011121314151617181920
  1. /// 对数字或金额的格式化
  2. class NumberFormatUtil {
  3. /// 格式化金额,每三位数分割一个逗号,1000 -> 1,000
  4. static String formatMoney(int number) {
  5. List<String> parts = [];
  6. String numberString = number.toString();
  7. while (numberString.length > 3) {
  8. parts.add(numberString.substring(numberString.length - 3));
  9. numberString = numberString.substring(0, numberString.length - 3);
  10. }
  11. parts.add(numberString);
  12. return parts.reversed.join(",");
  13. }
  14. }