【发布时间】:2014-12-11 11:40:07
【问题描述】:
当使用 VariantChangeType() 将其转换为双精度时,我有值为“2.550000”的 VT_R4/浮点类型变体,将 VT_R8/双精度类型值变为“2.54999999998”。
::VariantChangeType(&var, &var, 0, VT_BSTR);
::VariantChangeType(&var, &var, 0, VT_R8);
double dOutputValue = var.dblVal;
this double when is when is rounded of using
output.Format(_T("%3.1f"), dOutputValue);
给出的值是 2.5,而不是预期的 2.6。
请提出建议。
【问题讨论】:
-
谷歌“浮点精度”。 2.55 不能用浮点数精确表示。
标签: c++ winapi com double rounding