Converting Double to String in C++

前端 未结 3 1958
迷失自我
迷失自我 2020-12-31 12:00

I am having some issues trying to convert a double to C++ string. Here is my code

std::string doubleToString(double val)
{
    std::ostringstream out;
    ou         


        
3条回答
  •  渐次进展
    2020-12-31 12:55

    #include 
    using namespace std;
    // ...
    out << fixed << val;
    // ...
    

    You might also consider using setprecision to set the number of decimal digits:

    out << fixed << setprecision(2) << val;
    

提交回复
热议问题