C ++货币输出 [英] C++ currency output
本文介绍了C ++货币输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在正在上一门C ++课程,并完成了我的最终作业。但是,有一件事困扰着我:
I am taking a C++ course right now and have completed my final assignment. However there is one thing that is bugging me:
尽管我具有针对特定输出进行测试的正确输出,但 basepay
应为 133.20
,并显示为 133.2
。有没有办法让它显示额外的0而不是将其保留?
Though I have the correct outputs for the testing on a particular output, the basepay
should be 133.20
and it is displaying as 133.2
. Is there a way to have this display the extra 0 rather than leaving it off?
任何人都知道这是否可行以及如何做到?预先谢谢
Anyone know if it's possible and how to do it? Thank you in advance
我的代码如下:
cout<< "Base Pay .................. = " << basepay << endl;
cout<< "Hours in Overtime ......... = " << overtime_hours << endl;
cout<< "Overtime Pay Amount........ = " << overtime_extra << endl;
cout<< "Total Pay ................. = " << iIndividualSalary << endl;
cout<< endl;
cout<< "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" <<endl;
cout<< "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%" <<endl;
cout<< "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" <<endl;
cout<< "%%%% Total Employee Salaries ..... = " << iTotal_salaries <<endl;
cout<< "%%%% Total Employee Hours ........ = " << iTotal_hours <<endl;
cout<< "%%%% Total Overtime Hours......... = " << iTotal_OvertimeHours <<endl;
cout<< "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout<< "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
推荐答案
使用 cout.precision 设置精度,然后已固定以切换定点模式:
use cout.precision to set precision, and fixed to toggle fixed-point mode:
cout.precision(2);
cout<< "Base Pay .................. = " << fixed << basepay << endl;
这篇关于C ++货币输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文