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
Unless stated otherwise, the documentation on this site reflects Dart 3.6.0. Page last updated on 2025-01-27. View source or report an issue.