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?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-03-07. View source or report an issue.