toDecimal function

int toDecimal(
  1. int octal,
  2. String type, [
  3. int? max
])

Convert an octal value into a decimal value octal the octal value to convert type a string describing this octal value, used for context in error messages max the maximum decimal value allowed

Implementation

int toDecimal(int octal, String type, [int? max]) {
  try {
    final decimal = oct2dec(octal);
    if (max != null && decimal > max) {
      throw ArgumentError(
          '$type ($octal) cannot be larger than ${dec2oct(max)}.');
    }
    return decimal;
  } on InvalidOctalNumber {
    throw ArgumentError('$type ($octal) is not a valid octal number.');
  }
}