C ++如何输出带小数点后至少一个数字的数字 [英] C++ How to output number with at least one number behind the decimal mark
本文介绍了C ++如何输出带小数点后至少一个数字的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使我的程序输出一个至少在小数点C后面加一个数字的数字?
输出:
1 = 1.0或1.25 = 1.25或2.2 = 2.2或3.456789 = 3.456789
How can I make my program output a number with at least one number behind the decimal mark C++? Output: 1 = 1.0 or 1.25 = 1.25 or 2.2 = 2.2 or 3.456789 = 3.456789
预先感谢
推荐答案
使用 showpoint
强制打印小数点
double x = 1.0;
std::cout << std::showpoint << x << "\n";
后跟 0
必须满足流的精度。
It will be followed by the number of 0
required to satisfy the precision of the stream.
这篇关于C ++如何输出带小数点后至少一个数字的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文