【发布时间】:2014-01-10 02:29:56
【问题描述】:
我在 Dart 中遇到整数除法问题,因为它给了我错误:'Breaking on exception: type 'double' is not a subtype of type 'int' of 'c'。 p>
下面是代码:
int a = 500;
int b = 250;
int c;
c = a / b; // <-- Gives warning in Dart Editor, and throws an error in runtime.
如您所见,我期望结果应该是 2,或者说,即使 'a' 或 'b' 的除法会产生浮点/双精度值,它也应该直接转换为整数值,而不是像那样抛出错误。
我有一个使用 .round()/.ceil()/.floor() 的解决方法,但这在我的程序中是不够的,这个小操作很关键,因为它在一个游戏中被调用了数千次更新(或者你可以在 requestAnimationFrame 中说)。
我还没有找到任何其他解决方案,有什么想法吗?谢谢。
飞镖版本:1.0.0_r30798
【问题讨论】:
标签: dart