我的代碼: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