Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果位数为 7 或更多,浮点数或双精度数总是以科学计数法给出答案。就像一个十进制数10000000.5,它给出1e-08了一些东西。我想知道我们是否可以10000000.5在不添加任何新头文件的情况下进行打印。
10000000.5
1e-08
如果要打印到cout,请使用
cout
std::cout.setf( std::ios::fixed, std::ios::floatfield );
看到它的工作。
您可能还想std::cout.precision(1)设置小数点后的位数。
std::cout.precision(1)
printf("%.1f", someFloat)如果您想要一位小数,应该为您执行此操作。如果你想要n十进制数字,那么使用%.nf
printf("%.1f", someFloat)
n
%.nf