#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
long double n;
cin>>n;
cout<<setprecision(4)<<fixed<<scientific<<n;
return 0;
}
例如:如果我在程序中输入256之类的东西,我得到2.5600e + 002作为输出。但是我想打印2.5600 *(10 ^ 2)。我还希望能够控制显示多少位数字小数点后。
有人可以帮我吗?
void PrintScientific(long double d) {
int e = 0;
if(d < 1 && d > -1) {
for(e = 0; d*10 < 10 && d*10 > -10; e--) {
d *= 10;
}
} else {
for(e = 0; d/10 > 1 || d/10 < -1; e++) {
d /= 10;
}
}
std::cout << std::setprecision(4) << std::fixed << d << "*10^" << e;
}