gpt4 book ai didi

C++ 帮助从字符串中设置 setf floatfield

转载 作者:行者123 更新时间:2023-11-28 03:50:15 28 4
gpt4 key购买 nike

*mit = 13311
std::istringstream iss(*mit);
double temp;
iss.setf(ios::fixed, ios::floatfield);
iss.precision(15);
iss >> temp;

std::cout<<"temp "<<temp<<endl;
std::stringstream ss;
ss<<temp / 1024;

我试过设置精度/不设置精度,我仍然得到 12.999,而不是 12.9990234375请告知我做错了什么?谢谢。安德鲁

最佳答案

cout 中添加 std::setprecision( 15 )

 std::cout<< "temp " << std::setprecision( 15 ) << temp <<endl;

编辑:抱歉,如果我误会了你。您希望看到打印出 12.9990234375 或者您希望 ss12.9990234375 ?如果是第二个,则制作:

ss << std::setprecision(15) << temp / 1024;

关于C++ 帮助从字符串中设置 setf floatfield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5792111/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com