2 c++ floating-point visual-c++
#include <iostream>
int main()
{
float test = 12535104400;
std::cout << test;
std::cin.get();
return 0;
}
//on msvc 2010 this ouputs: 1.25351e+010
Run Code Online (Sandbox Code Playgroud)
我希望它只输出"12535104400"或换句话说,输出没有前导零的人类可读格式,但输出数字的完整值.
您需要包括<iomanip>:
int main()
{
const double test = 12535104400;
std::cout << std::fixed << std::setprecision(0) << test;
std::cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
std::fixed 是使用定点精度的操纵器(非科学记数法)std::setprecision(0) 设置小数点后显示的位数无法准确表示特定数字,例如,请尝试以下操作:
float v = 12535104400;
cout.precision(0);
cout << fixed << v << endl;
Run Code Online (Sandbox Code Playgroud)
你会看到它输出:12535104512