avoid_js_rounded_ints
Avoid JavaScript rounded ints.
This rule is available as of Dart 2.0.
Details
#AVOID integer literals that cannot be represented exactly when compiled to JavaScript.
When a program is compiled to JavaScript int
and double
become JavaScript
Numbers. Too large integers (value < Number.MIN_SAFE_INTEGER
or
value > Number.MAX_SAFE_INTEGER
) may be rounded to the closest Number value.
For instance 1000000000000000001
cannot be represented exactly as a JavaScript
Number, so 1000000000000000000
will be used instead.
BAD:
int value = 9007199254740995;
GOOD:
BigInt value = BigInt.parse('9007199254740995');
Usage
#To enable the avoid_js_rounded_ints
rule,
add avoid_js_rounded_ints
under linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- avoid_js_rounded_ints
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。