Hi, I've tried looking this up but couldn't find an answer to my question, and decided to post a thread asking for help. So I've tried using something like
|
cout << setprecision(2) << price;
|
and it works perfectly. Instead of displaying "14.5896532" from calculation, it will only display "14.58" which is exactly what I want. However, I noticed that whenever I use "fixed setprecision" on part of the code, everything goes to having 2 decimal places, and I don't want that. For example, other than this part, I want the user to be able to enter a number and display exactly what they enter unless it goes beyond 2 decimal points.
When the user inputs "14", it should display "14", not "14.00";
when the user inputs "14.5", it should display "14.5", not "14.50";
when the user inputs "14.5236581", it should display "14.52".
when the user inputs "14.5256581", it should display "14.53"
So basically, I want in one section, the number displays do exactly what "fix setprecisions(2)", and on the other part(s), the number displays exactly what the user types in, be it integer or decimal, unless it has over 2 decimals then round off to 2 decimals. Can anyone give an example on how this can be accomplished? Thanks in advance.