我有一段代码以这种形式显示结果:示例
Amount: 10
Total Amount: 200
Tax: 30
Net Balance: 2000
我希望显示结果(例如数学类型)从右侧开始,小数点后有 2 个零 (00)。示例
Amount: 10.00
Total Amount: 200.00
Tax: 30.00
Net Balance: 2000.00
我正在为此使用 double int,但我真的不知道如何设置从右侧开始的结果量,其中包含一个序列以及一个点和零。
最佳答案
您可以结合 <iomanip>
中的一些设置:
std::cout << std::fixed; // formatting floating-point numbers
std::cout << std::setprecision(2); // number of floating-point digits
std::cout << std::setw(10); // width of the whole output string
std::cout << std::right; // padding to the right
关于c++ - 显示正确的整数结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28277074/