在 C++ 中,我使用以下语句来显示输出:
// example
float x = 0.66004;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << x;
我的输出看起来像
0.66
如何防止显示小数点前的零?我要:
.66
最佳答案
std::string Foo = std::to_string(0.553);
std::size_t it = Foo.find(".");
if (it != std::string::npos)
{
std::cout<<Foo.erase(0, it);
}
关于c++ - 防止在C++中显示小数点前的零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19214421/