parse method

double parse (
  1. String source,
  2. [@deprecated double onError(
    1. String source
    )]
)
override

Parse source as an double literal and return its value.

Accepts an optional sign (+ or -) followed by either the characters "Infinity", the characters "NaN" or a floating-point representation. A floating-point representation is composed of a mantissa and an optional exponent part. The mantissa is either a decimal point (.) followed by a sequence of (decimal) digits, or a sequence of digits optionally followed by a decimal point and optionally more digits. The (optional) exponent part consists of the character "e" or "E", an optional sign, and one or more digits. The source must not be null.

Leading and trailing whitespace is ignored.

If the source string is not a valid double literal, the onError is called with the source as argument, and its return value is used instead. Throws a FormatException if the source string is not valid and no onError is provided.

Examples of accepted strings:

"3.14"
"  3.14 \xA0"
"0."
".0"
"-1.e3"
"1234E+7"
"+.12e-9"
"-NaN"

The onError parameter is deprecated and will be removed. Instead of double.parse(string, (string) { ... }), you should use double.tryParse(string) ?? (...).

Implementation

external static double parse(String source,
    [@deprecated double onError(String source)?]);

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-core/double/parse.html