percentage function

double percentage({
  1. required dynamic value,
  2. required dynamic total,
  3. int? round,
})

Calculate the percentage of a number, and round the result if pass the optional parameter

Implementation

double percentage(
    {required dynamic value, required dynamic total, int? round}) {
  var valueParsed = toDouble(value);
  var totalParsed = toDouble(total);

  var result = (valueParsed * 100) / totalParsed;
  if (round == null) {
    return result;
  } else {
    return fixedDecimais(value: result, decimalPlaces: round);
  }
}