/// 对数字或金额的格式化 class NumberFormatUtil { /// 格式化金额,每三位数分割一个逗号,1000 -> 1,000 static String formatMoney(int number) { List 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(","); } //对比带. 的版本号大小 static int compareVersionNumbers(String version1, String version2) { List v1 = version1.split('.').map(int.parse).toList(); List v2 = version2.split('.').map(int.parse).toList(); int minLength = v1.length < v2.length ? v1.length : v2.length; for (int i = 0; i < minLength; i++) { if (v1[i] < v2[i]) { return -1; // version1 < version2 } else if (v1[i] > v2[i]) { return 1; } } if (v1.length < v2.length) { return -1; } else if (v1.length > v2.length) { return 1; // version1 > version2 } return 0; //version1 = version2 } }