显示错误值的 Int 变量 - Android
Int variable showing wrong value - Android
这段代码给出了错误的输出,我不确定为什么,我要疯了。
float correctX=((getWidth()/599)*x);
float correctY=((getHeight()/740)*y);
我得到的结果是:x = 520
y = 900.
和logcat输出日志:DETAILS------------宽度:1080.高度:1533.X值:520.Y值:450
为什么?我不知道,我快疯了,我什至不知道它的语法是否正确哈哈。
我用android工作室顺便说一下
这是因为 integer division(转到 混淆部门)不准确。为 float
设置一些值以使其更好。
int correctX = (int)((1080f/599)*520);
或
只需将 correctX
更改为 float
float correctX = (1080f/599)*520;
这段代码给出了错误的输出,我不确定为什么,我要疯了。
float correctX=((getWidth()/599)*x);
float correctY=((getHeight()/740)*y);
我得到的结果是:x = 520 y = 900.
和logcat输出日志:DETAILS------------宽度:1080.高度:1533.X值:520.Y值:450
为什么?我不知道,我快疯了,我什至不知道它的语法是否正确哈哈。
我用android工作室顺便说一下
这是因为 integer division(转到 混淆部门)不准确。为 float
设置一些值以使其更好。
int correctX = (int)((1080f/599)*520);
或
只需将 correctX
更改为 float
float correctX = (1080f/599)*520;