Skip to main content

prefer_int_literals

Details about the 'prefer_int_literals' diagnostic produced by the Dart analyzer.

Unnecessary use of a 'double' literal.

Description

#

The analyzer produces this diagnostic when a double literal's value has a fractional part of 0 (such as 8.0) and is used where the context type is double.

In these cases, you can use an int literal instead, because it would evaluate to the same double value.

Examples

#

The following code produces this diagnostic because the literal 8.0 is used to initialize a variable of type double, but its value has a fractional part of 0:

dart
double d = 8.0;

The following code produces this diagnostic because the literal 7.1e2 evaluates to 710.0, which has a fractional part of 0, and is used to initialize a variable of type double:

dart
double d = 7.1e2;

Common fixes

#

Replace the double literal with an equivalent int literal:

dart
double d = 8;
dart
double d = 710;