C++ 在C+中舍入十进制文件时出现问题+;使用setprecision

C++ 在C+中舍入十进制文件时出现问题+;使用setprecision,c++,user-defined-functions,decimal-point,C++,User Defined Functions,Decimal Point,可能重复: 这是我正在使用的函数 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

可能重复:

这是我正在使用的函数

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;
}
char*四舍五入(双数值,整数位小数)
{
小数点=小数点+1;
std::stringstreams2;

s20.89425不能用二进制浮点精确表示;最接近的精确表示值为0.89424999999999999989341858963598497211933135986328125,正确舍入为十进制0.8942

如果要查看十进制舍入行为,请使用定点或十进制浮点