avoid_js_rounded_ints
Avoid JavaScript rounded ints.
此规则自 Dart 2.0 版本起可用。
详情
#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');
使用方法
#要启用 avoid_js_rounded_ints
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 avoid_js_rounded_ints
:
linter:
rules:
- avoid_js_rounded_ints
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.