formatNum static method

dynamic formatNum(
  1. double num,
  2. int postion
)

Implementation

static formatNum(double num, int postion) {
  if ((num.toString().length - num.toString().lastIndexOf(".") - 1) <
      postion) {
    //小数点后有几位小数

    print(num.toStringAsFixed(postion)
        .substring(0, num.toString().lastIndexOf(".") + postion + 1)
        .toString());
  } else {
    print(num.toString()
        .substring(0, num.toString().lastIndexOf(".") + postion + 1)
        .toString());
  }
}