percentOf method

double percentOf(
  1. T total
)

Returns the percentage of the current number in relation to the total number. If the total number is null or 0, it returns 0. Otherwise, it returns the percentage value. The percentage is calculated as a double value between 0 and 1, where 1 represents 100%.

Implementation

double percentOf(T total) {
  if (total == null || total == 0) {
    return 0;
  } else {
    return (this! / total);
  }
}