A
abdul_n_khan
Hello,
I have a basic question related to datatypes.
I am trying to read a value using Microsoft's ADO recordset from a
field (lets call it 'Price') with datatype decimal(19,6) => 19 =
Precision, 6 = Scale
1) When I read this field into float datatype. I get a value 1.9000,
which is correct. But when I read its value in a double datatype I get
1.8999999761581.
2) My second question is related to multiplication.
Should it cause any problem?
dblPrice =1.23333;
Amount = 91000000;
PricedAmount= dblPrice * Amount
PricedAmountshould have 112233030
But i am getting 112230300 (thus I am loosing precision).
Here is the implementation of Multiplication operator of CCurrency
class
CCurrency CCurrency:perator*(float nOperand) const
{
if (!GetStatus() == valid)
return *this;
CCurrency curOperand;
VarCyFromR4(nOperand,&curOperand.m_cur);
CCurrency curResult;
HRESULT hr = VarCyMul(*this, curOperand,&curResult.m_cur);
if FAILED(hr)
{
curResult.SetStatus(invalid);
curResult.m_cur.int64 = 0;
}
return curResult;
}
CCurrency CCurrency:perator*(double nOperand) const
{
if (!GetStatus() == valid)
return *this;
CCurrency curOperand;
VarCyFromR8(nOperand,&curOperand.m_cur);
CCurrency curResult;
HRESULT hr = VarCyMul(*this, curOperand,&curResult.m_cur);
if FAILED(hr)
{
curResult.SetStatus(invalid);
curResult.m_cur.int64 = 0;
}
return curResult;
}
I have a basic question related to datatypes.
I am trying to read a value using Microsoft's ADO recordset from a
field (lets call it 'Price') with datatype decimal(19,6) => 19 =
Precision, 6 = Scale
1) When I read this field into float datatype. I get a value 1.9000,
which is correct. But when I read its value in a double datatype I get
1.8999999761581.
2) My second question is related to multiplication.
Should it cause any problem?
dblPrice =1.23333;
Amount = 91000000;
PricedAmount= dblPrice * Amount
PricedAmountshould have 112233030
But i am getting 112230300 (thus I am loosing precision).
Here is the implementation of Multiplication operator of CCurrency
class
CCurrency CCurrency:perator*(float nOperand) const
{
if (!GetStatus() == valid)
return *this;
CCurrency curOperand;
VarCyFromR4(nOperand,&curOperand.m_cur);
CCurrency curResult;
HRESULT hr = VarCyMul(*this, curOperand,&curResult.m_cur);
if FAILED(hr)
{
curResult.SetStatus(invalid);
curResult.m_cur.int64 = 0;
}
return curResult;
}
CCurrency CCurrency:perator*(double nOperand) const
{
if (!GetStatus() == valid)
return *this;
CCurrency curOperand;
VarCyFromR8(nOperand,&curOperand.m_cur);
CCurrency curResult;
HRESULT hr = VarCyMul(*this, curOperand,&curResult.m_cur);
if FAILED(hr)
{
curResult.SetStatus(invalid);
curResult.m_cur.int64 = 0;
}
return curResult;
}