C++11 std::to_string(double) – No trailing zeros

If all you want to do is remove trailing zeros, well, that’s easy.

std::string str = std::to_string (f);
str.erase ( str.find_last_not_of('0') + 1, std::string::npos );
str.erase ( str.find_last_not_of('.') + 1, std::string::npos );

Leave a Comment