为什么我输入的数字只读到6个有效数字
Why are the numbers I input only read to 6 significant figures?
我正在尝试运行以下程序,它可以工作,但当我输入的值超过小数点后6位时,它会被四舍五入/截断,例如2.999999-->3。我如何设置它,使它停止执行此操作?
int main()
{
double n=0, x=0;
while (cin >> n >> x) //will keep going until an integer is not entered
{
cout << "You entered the two integers " << x << " and " << n << endl;
if (x-n <= (1.0/10000000) && n-x <= (1.0/10000000))
cout << "The numbers are almost equal" << endl;
}
return 0;
}
您可以使用std::setprecision
:更改打印值的精度
cout << "You entered the two integers " << setprecision(20) << x
<< " and " << n << endl;
链接到ideone。
相关文章:
- 最高有效数字侧的第N位
- 如何知道n!是否可以表示为三个连续数字的乘法?
- 无符号的 int 到有效数字
- 将数字表示为两个三角形数字的总和
- 无法理解代码背后的逻辑,这是在两个给定数字之间生成素数的优化问题
- 如何知道文本文件中的输入是否是 C++ 中的有效数字
- C++个大数字
- 如何将boost::asio::ip::address_v6 ip转换为2个uint64_t数字,并从2个uint 64
- 在 std::unordered_set <double>中插入多个非数字
- 两个大数字的模型存储为字符串
- C++将存储在链表中的两个大数字相乘
- 有没有办法在值数组中随机添加或减去两个特定数字或更多
- 2 个给定数字之间的双精度密度
- 给定n个数字,编写一个例程,以在4个连续数字之间找到最大的数字
- C 如何进行计数循环,该循环确定两个输入数字中的哪个是最低的,并且从那里计数
- 打印出前888个快乐数字
- 应用一组 N 个函数的第一个有效函数
- 将数字n分为k个不同数字的总和
- 为什么我输入的数字只读到6个有效数字
- 如何检查两个数字是否在浮点类型的精度限制的有效数字"x"范围内?