我是 C++ 新手,我的第一个程序有问题。我正在尝试将两个 float 相乘,结果总是显示为 1.1111e+1,其中 1s 是随机数。下面是我写的小程序。
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main()
{
float bank;
float dollor;
cout<<"Enter amount of $ deposited at Bank: ";//the data to input is 5000
cin>>bank;
cout<<"Enter current $ price: ";//1usd = 800mmk: the data to input is 800
cin>>dollor;
bank*=dollor;//all deposited $ to local currency
cout<<"Result is "<<bank;
getch();
}
这个程序的结果是 4e+006。
ps: 我声明为 float 以便在某个时候输入 float。 请帮我解决这个程序我错了的地方。谢谢大家..
最佳答案
4e+006
是 scientific notation 4000000
,这是 5000*800
的正确答案。
具体来说,4e+006
代表4 * 10**6
,其中10**6
是十的六次方.
要使用定点表示法,您可以像这样更改您的程序:
#include <iomanip>
...
cout << "Result is " << fixed << bank;
关于c++ - 在 C++ 中乘以两个 float 给我非数字结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8534936/