小编Jeb*_*hew的帖子

将非常小的数字舍入为零(c ++)

在C++中是否有任何命令可以制作,

1.354322e-23
Run Code Online (Sandbox Code Playgroud)

0
Run Code Online (Sandbox Code Playgroud)

这是我的(简单)程序

#include "stdafx.h"
#include <iostream>
#include<iomanip>

int main()
{
    float x;
    std::cin >> x;
    std::cout << x << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我输入值时,

2.2356e-17
Run Code Online (Sandbox Code Playgroud)

它给,

2.2356e-017
Run Code Online (Sandbox Code Playgroud)

std::setprecision 不会工作......

编辑: 好的,这是我的问题.我创建了一个程序,可以给出sin costan值.

对于cos 90,我希望它为0而不是-4.311e-008

继承人我的真实计划

#include "stdafx.h"
#include <iostream>
#include<iomanip>

float Pi()
{
  float pi = (atan(1) * 4);
  return pi;
}

int Selector()
{
  using namespace std;
  cout << "Type:\t1 for Degrees\n\t2 for Radians\n\t3 for Gradians\n\nYour Choice : ";
  int x; …
Run Code Online (Sandbox Code Playgroud)

c++ rounding

-5
推荐指数
1
解决办法
2505
查看次数

标签 统计

c++ ×1

rounding ×1