Result of casting double to int is wrong

ぐ巨炮叔叔 提交于 2019-12-01 05:20:45

Just about every modern computer uses a binary representation for floating-point numbers.

Just as 1/3 = 0.33333333... can't be represented exactly as a decimal fraction, so 1/10 (and hence most non-integer decimal values, including 1.4) can't be represented exactly as a binary fraction. It will instead be represented by the nearest representable value, which may be slightly more or less than the "true" value.

You might want to round to the nearest integer instead: (int)(PriorityJob * 100.0 + 0.5)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!