formatDouble method
String
formatDouble(
{ - dynamic nullTxt = "-",
})
Implementation
String formatDouble({nullTxt = "-"}) {
if (this == null) {
return nullTxt;
}
double num;
try {
num = double.parse(toString());
} catch (e) {
loggerNoStack.i("转换异常:$e");
return nullTxt;
}
if ((num.toString().length - num.toString().lastIndexOf(".") - 1) < 2) {
//小数点后有几位小数
return num.toStringAsFixed(2)
.substring(0, num.toString().lastIndexOf(".") + 2 + 1)
.toString();
} else {
return num.toString()
.substring(0, num.toString().lastIndexOf(".") + 2 + 1)
.toString();
}
}