将双精度的科学记数法附加到 ostringstream 时如何关闭它?

How to turn off scientific notation for double when appending it to ostringstream?

本文关键字:ostringstream 何关闭 双精度      更新时间:2023-10-16

>我有一个小函数,可以将双精度转换为 std::string:

std::string convertDoubleToString( double value ) {
std::ostringstream ostr;
ostr << value;
return ostr.str();
}

我不想在这里使用科学记数法。在这种情况下,我该怎么做?我可以使用std::fixed或cout.setprecision,但它仅适用于std::cout,但我如何在我的情况下使用它?

像这样使用 std::fix 操纵器:

ostr << std::fixed << value;