prefer_ int_ literals
Prefer int literals over double literals.
Details
#DO use int literals rather than the corresponding double literal.
BAD:
dart
const double myDouble = 8.0;
final anotherDouble = myDouble + 7.0e2;
main() {
someMethod(6.0);
}
GOOD:
dart
const double myDouble = 8;
final anotherDouble = myDouble + 700;
main() {
someMethod(6);
}
Enable
#
To enable the prefer_int_literals
rule, add prefer_int_literals
under
linter > rules in your analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- prefer_int_literals
If you're instead using the YAML map syntax to configure linter rules,
add prefer_int_literals: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
prefer_int_literals: true
Was this page's content helpful?
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.