我在DART中使用整数除法时遇到问题,因为它给出错误:'Breaking on exception: type 'double' is not a subtype of type 'int' of 'c'.'
下面是以下代码:
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()/.loor()来解决问题,但是这还不够,因为这个小操作很关键,因为它在一个游戏更新中被调用了数千次(或者您可以说在requestAnimationFrame中调用).
我还没有找到其他解决办法,知道吗?谢谢
DART版本:1.0.0_r30798