我的代码:C++ printf舍入?
// Convert SATOSHIS to BITCOIN
static double SATOSHI2BTC(const uint64_t& value)
{
return static_cast<double>(static_cast<double>(value)/static_cast<double>(100000000));
}
double dVal = CQuantUtils::SATOSHI2BTC(1033468);
printf("%f\n", dVal);
printf("%s\n", std::to_string(dVal).data());
谷歌输出:0.01033468
程序输出:0.010335既为printf
和std::to_string
调试器输出:0.01033468
做printf
和std::to_string
整数? 如何获得正确值的字符串?
为'to_string()'和(我猜'printf')的默认精度为6位小数(看到这一点:http://stackoverflow.com/questions/14520309/the-precision-of-stdto-stringdouble和http:// stackoverflow。com/questions/16605967/set-precision-of-stdto-string-when-conversion-floating-point-values) – Nim
“google”(wtf?)和调试器输出都没有任何意义。 –
对不起,错误的复制/粘贴。更新。 如果您使用Google Calc,Google输出就是您所得到的结果。 感谢您的回答@Nim – PeeS