2
가능한 중복 사용하여 C++에서 소수점 fileds 라운딩 동안 :
다음
Does setprecision in c++ round? If so why am I seeing this?문제 setprecision에게
내가
이char* round(double value, int decimal_places)
{
decimal_places = decimal_places+1;
std::stringstream s2;
s2 << std::setprecision(decimal_places) << std::setiosflags(std::ios_base::fixed) << value;
std::string st = s2.str();
return st;
}
내 입력 값이 사용하고 기능입니다 0.89425이며 소수점 이하 자릿수는 4입니다.
내 출력은 0.8942이지만 0.8943이 필요합니다. 즉, 필요한 소수 자릿수 다음 자리가 다음 값보다 작 으면 출력이 다음 값으로 반올림되어야합니다.