coost icon indicating copy to clipboard operation
coost copied to clipboard

浮点数转字符串没有四舍五入?

Open cailei77 opened this issue 1 year ago • 3 comments

double f = 3.14159265; fastring str; str << dp::_n(f, 4); cout << str << std::endl; 这段代码输出的结果是3.1415,按照精度要求应该是3.1416吧?

cailei77 avatar Jul 16 '23 05:07 cailei77

if we convert rad to degree, rang will over 180, 180.0004, you can use round ,floor, or ceil ,before string conversion.

youngday avatar Jul 16 '23 11:07 youngday

if we convert rad to degree, rang will over 180, 180.0004, you can use round ,floor, or ceil ,before string conversion. 我只是说浮点数转换为字符串的显示精度问题,计算精度应该不受影响

cailei77 avatar Jul 17 '23 01:07 cailei77

double f = 3.14159265; fastring str; str << dp::_n(f, 4); cout << str << std::endl; 这段代码输出的结果是3.1415,按照精度要求应该是3.1416吧?

现在没有考虑四舍五入

idealvin avatar Jul 18 '23 10:07 idealvin