문제

In C++, I'm using the following statements to display output:

// example
float x = 0.66004;
cout.setf(ios::fixed);  
cout.setf(ios::showpoint);  
cout.precision(2);
cout << x;

My output looks like

0.66

How can I prevent the zero before the decimal from being displayed? I want:

.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);
}

다른 팁

One possible solution is converting x to string (more options) and cut off everything before the decimal.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top