我正在尝试编写一个函数来检查T分数值,并填充5x5数组的一半。
public void calcTScores()
{
double temp = 0;
double tempSp = 0;
int n = 24;
this.tScores = new String [5][5];
for (int i = 0; i< this.Headers.length; i++){
for (int j = 0; j<this.Headers.length; j++)
{
if(i < j)
{
tempSp += (n-1)*this.SD[i] * this.SD[i] + (n-1)*this.SD[j] * this.SD[j];
tempSp = tempSp/(n+n-2);
tempSp = Math.sqrt(tempSp);
temp = tempSp * Math.sqrt(0.0833);
System.out.println(Math.sqrt(1/12));
temp = ((this.Mean[i] - this.Mean[j])/temp);
if(temp > 2.25 || temp< -2.25)
{
this.tScores[i][j] = "Y";
}
else
{
this.tScores[i][j] = "N";
}
temp = 0;
tempSp = 0;
}
}
}
}知道为什么Math.sqrt(0.0833)和Math.sqrt(1/12)会得到不同的值吗?
当我将1/24和1/24值相加并采用sqrt时,T得分保持为零,但当我插入实际的小数时,它会给出我所期望的答案
你知道为什么会发生这种情况吗?
发布于 2021-03-24 10:46:27
1/12==0,按整数除法
发布于 2021-03-24 10:47:41
Math.sqrt没有任何问题。您传递给它的是数字0。
Math.sqrt(1/12)1/12是对两个整数(即1和12)的除法运算,因此它将产生一个整数结果。12等于1的0次,因此整数结果为0。因此,您的表达式是
Math.sqrt(0)考虑一下
Math.sqrt(1.0/12.0)发布于 2021-03-24 10:55:37
Math.sqrt(1/12d)通过将一个操作数转换为双精度,将1/12转换为双精度。
https://stackoverflow.com/questions/66774020
复制相似问题