0

I am trying to print a decimal number however when printing the trailing zeros are always removed.

e.g. If I input the number 100 I would like it to print 100.00 If I input the number 12.506 I would like it to print 12.50

For this program I was limited to the iostream and fstream libraries. I tried using precision but it removes the trailing zeros.

  • 1
    Use `fixed` as well as `setprecision`, `cout << fixed << setprecision(2) << 100.0;` – john Aug 01 '20 at 19:24
  • I cannot use setprecision since that requires iomanip library and I could only use iostream and fstream. However I was able to figure out my problem by adding "fixed" – Randell Persad Aug 01 '20 at 19:52
  • Very strange but `cout.precision(2)` works just as well. – john Aug 01 '20 at 19:54
  • Surely you would prefer 12.506 to print 12.51? That is what you will get, anyway. – TonyK Aug 02 '20 at 00:34

0 Answers0