W3cubDocs

/Dart 2

tryParse method

num tryParse (String input)

Parses a string containing a number literal into a number.

Like parse except that this function returns null for invalid inputs instead of throwing.

Implementation

static num tryParse(String input) {
  String source = input.trim();
  // TODO(lrn): Optimize to detect format and result type in one check.
  return int.tryParse(source) ?? double.tryParse(source);
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-core/num/tryParse.html