本文介绍了C ++ Handle -0.0 from Database的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我正在研究一些C ++代码,我需要从数据库中读取数据,如果数据库值非零,那么我需要应用一些其他逻辑。
但是在数据库中有一些正在计算的值,可以得出-0.0。而这个负零被视为C ++双变量中的垃圾值。我已经在构造函数中将值初始化为0.0。
At present I am working on piece of C++ code in which I need to read data from a database, and if database value is non-zero, then I need to apply some further logic.
But in the database there are values which are being calculated and can come out as -0.0. And this negative zero is being treated as Garbage value in C++ double variable. I have already initialized the value as 0.0 in constructor.
// This list is being populated from Database
for (Sample::List<BalanceSheet>::Iterator i((Sample::List<BalanceSheet> &) Balance.Entries()); i.HaveItem(); ++i)
{
if (SomeCondition != "")
{
// This is where am getting Garbage values since GetBalance() returns -0.0
if (i->GetBalance() != 0)
{
DoOperation();
}
}
}
推荐答案
if (i->GetBalance() != 0) // This is a bug waiting to happen
请在此处阅读: []
Read here: https://isocpp.org/wiki/faq/newbie#floating-point-arith[^]
这篇关于C ++ Handle -0.0 from Database的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!