Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 Qt,我的负整数没有正确舍入。这是我的源代码:
if (intCalibrate < 0) { intCalibrateCalculate = (intCalibrate * 100.0f * 5.0f/9.0f - 0.5f) + 65535; } else { intCalibrateCalculate = (intCalibrate * 100.0f * 5.0f/9.0f + 0.5f); }
如果它是正数,则它是正确舍入的。不知道为什么负面不起作用。
我想到了。
if (intCalibrate < 0) { intCalibrateCalculate = (intCalibrate * 100.0f * 5.0f/9.0f - 0.5f); intCalibrateCalculate = intCalibrateCalculate + 65535; } else { intCalibrateCalculate = (intCalibrate * 100.0f * 5.0f/9.0f + 0.5f); }