parse static method

Number parse(
  1. String input
)

Parses a string containing a number literal into a number. The method first tries to read the input as integer (similar to int.parse without a radix). If that fails, it tries to parse the input as a decimal (similar to Decimal.parse). If that fails too, it throws FormatException.

Implementation

static Number parse(String input) {
  var source = input.trim();

  var parsedInt = int.tryParse(source);
  if (parsedInt != null) {
    return Integer(parsedInt);
  }

  var decimalResult = Decimal.parse(
      source); //this throws FormatException, if input is not decimal number
  return decimalResult;
}