【发布时间】:2023-03-19 04:24:01
【问题描述】:
我将四个字节转换为浮点数,结果得到NaN,但我想要0.0 的值。我做错了什么?
这是我的代码:
public class abc
{
public static void main(String[] args)
{
int[] arry = { 255, 255, 255, 255 };
int num = ((arry[0] << 24) & 0xFF000000) | ((arry[1] << 16) & 0xFF0000)
| ((arry[2] << 8) & 0xFF00) | (arry[3] & 0xFF);
float f = Float.intBitsToFloat(num);
f= (float) ((f < 0 ? Math.ceil(f * 10) : Math.floor(f * 10)) / 10);
System.out.println(f);
}
}
【问题讨论】:
-
这个问题的上下文是什么?
标签: java floating-point core nan