getDecimalPlaces method

int getDecimalPlaces(
  1. double number
)

Implementation

int getDecimalPlaces(double number) {
  String numberString = number.toString();
  int decimalIndex = numberString.indexOf('.');
  if (decimalIndex == -1) {
    return 0; // 没有小数部分
  }
  return numberString.length - decimalIndex - 1;
}