formatMoney static method
每3位加逗号
Implementation
static String formatMoney(double money, {separate: 3}) {
String str = money.toStringAsFixed(2);
List<String> sub = str.split('.');
List val = List.from(sub[0].split(''));
//处理分割符
for (int index = 0, i = val.length - 1; i >= 0; index++, i--) {
// 除以三没有余数、不等于零并且不等于1 就加个逗号
if (index % separate == 0 && index != 0) {
val[i] = val[i] + ',';
}
}
return '${val.join('')}.${sub[1]}';
}