将它附加到 ostringstream 时如何关闭 double 的科学记数法?
How to turn off scientific notation for double when appending it to ostringstream?
我有一个小函数可以将 double 转换为 std::string:
std::string convertDoubleToString( double value ) {
std::ostringstream ostr;
ostr << value;
return ostr.str();
}
我不想在这里使用科学记数法。在这种情况下我该怎么做?我可以使用 std::fixed 或 cout.setprecision,但它仅适用于 std::cout 但我如何将它用于我的案例?
像这样使用 std::fixed 操纵器:
ostr << std::fixed << value;
我有一个小函数可以将 double 转换为 std::string:
std::string convertDoubleToString( double value ) {
std::ostringstream ostr;
ostr << value;
return ostr.str();
}
我不想在这里使用科学记数法。在这种情况下我该怎么做?我可以使用 std::fixed 或 cout.setprecision,但它仅适用于 std::cout 但我如何将它用于我的案例?
像这样使用 std::fixed 操纵器:
ostr << std::fixed << value;