【发布时间】:2015-12-19 23:12:23
【问题描述】:
我有这个:
#include <iostream>
#include <iomanip>
std::string ExampleInstance::RoundNumber(float result) {
std::string RoundResult;
std::cout << std::fixed << std::showpoint;
std::cout << std::setprecision(1);
std::cout << result << std::endl;
RoundResult = std::to_string(result);
return RoundResult;
}
我想给这个方法传递一个浮点数,将其四舍五入到小数点后一位,将其转换为字符串,然后返回。目前这对号码没有任何作用。
setPrecision 会更有效吗?我是 C++ 新手。
【问题讨论】:
标签: c++ rounding tostring floating-accuracy