两个 double 值。
double a=-324.000000
double b= 0.000000
if(a*b<0)
{
//number is less than 0
}
else
{
//number is greater than zero
}
它总是给出“小于零的数字”的输出。当我将它们相乘时,我得到的结果为“-0.000000”。但是结果应该是 0.000000。
最佳答案
This is not the result that I get .您确定问题不在其他地方吗?
你在评论中说“我试过 if(a==0.0){/* 但它从来没有进入这里!!*/}
。”看起来这个数字实际上不是 0。
关于c++ - 我如何在计算中避免 -0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20153771/