Widget.MaterialComponents.Button.TextButton.Snackbar
浮点数或两倍数我得到:0.666667;
我期望双精度会提高精度; 我如何获得更多类似的东西:0.666666666666667
编辑:并且我不必使用to_string来失去精度;
答案 0 :(得分:2)
我希望双精度更高
浮点类型的精度与文本表示中的十进制数字的精度是分开的概念。
您没有指定所需的精度,因此使用默认值。碰巧的是,默认值不是您任意期望的。您可以指定精度,例如:
std::cout.precision(15);
答案 1 :(得分:0)
setprecision
位于头文件#include<iomanip>
中,可让您设置小数精度。
例如:
#include <iostream>
#include <iomanip> // The precision manipulator is in this header file
int main()
{
double a = 2 , b = 3;
double answer = a/b;
std::cout << std::setprecision(15) << answer;
return 0;
}