Skip to main content
A double in Dart is a 64-bit double-precision floating-point number conforming to the IEEE 754 standard. It is a subclass of the abstract num type and is utilized to represent fractional numerical values, supporting both standard decimal and scientific notation.

Syntax and Initialization

A double can be instantiated using standard decimal literals, scientific notation, or implicitly from integer literals (as of Dart 2.1).
double standard = 3.14159;
double scientific = 1.42e5;         // Evaluates to 142000.0
double negativeScientific = 2.5e-3; // Evaluates to 0.0025
double implicitInteger = 42;        // Implicitly converted to 42.0

Special Values

Conforming to IEEE 754, the double class provides static constants to represent specific non-finite and boundary values.
double notANumber = double.nan;
double posInfinity = double.infinity;
double negInfinity = double.negativeInfinity;

// Boundary constants
double max = double.maxFinite; // 1.7976931348623157e+308
double min = double.minPositive; // 5e-324

Parsing and Conversion

Dart provides static methods for parsing strings into double objects, alongside instance methods for type conversion from other num types.
// Strict parsing; throws FormatException if invalid
double parsed = double.parse("3.14");

// Safe parsing; returns null if invalid
double? safeParsed = double.tryParse("NaN_String"); 

// Conversion from int
int integerValue = 5;
double converted = integerValue.toDouble();

Arithmetic Precision

Because Dart utilizes standard IEEE 754 representation, double arithmetic is subject to standard floating-point precision loss. It cannot precisely represent all base-10 fractional numbers.
double a = 0.1;
double b = 0.2;
double sum = a + b; // Evaluates to 0.30000000000000004

Core Properties and Methods

The double type inherits and implements various properties and methods for mathematical rounding, sign evaluation, and state checking.
double value = -7.5;

// State Evaluation
bool isNan = value.isNaN;           // false
bool isInfinite = value.isInfinite; // false
bool isFinite = value.isFinite;     // true
bool isNegative = value.isNegative; // true

// Mathematical Operations
double absolute = value.abs();      // 7.5
int rounded = value.round();        // -8 (Rounds to nearest integer)
int ceiled = value.ceil();          // -7 (Rounds towards positive infinity)
int floored = value.floor();        // -8 (Rounds towards negative infinity)
int truncated = value.truncate();   // -7 (Discards fractional digits)
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More