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