use_truncating_division
Use truncating division.
This rule is available as of Dart 3.6.
This rule has a quick fix available.
Details
#DO use truncating division, '~/', instead of regular division ('/') followed by 'toInt()'.
Dart features a "truncating division" operator which is the same operation as division followed by truncation, but which is more concise and expressive, and may be more performant on some platforms, for certain inputs.
BAD:
var x = (2 / 3).toInt();
GOOD:
var x = 2 ~/ 3;
Usage
#To enable the use_truncating_division
rule, add use_truncating_division
under linter > rules in your analysis_options.yaml
file:
linter:
rules:
- use_truncating_division
Unless stated otherwise, the documentation on this site reflects Dart 3.5.4. Page last updated on 2024-07-03. View source or report an issue.