1

new to stack overflow and c++

std::cout << std::fixed << "Starting Balance: $" << std::setprecision(2) << startbal << endl;
    std::cout<< "Annual Interest Rate: " << intrestrate << endl;
    std::cout << std::fixed << "Monthly Payment: $" << std::setprecision(2) <<monthlypay << endl;

Here I am trying to print from an array that I have, its printing mostly correct but I need the second line to not be affected by the setprecision so that the Annual Interest Rate will not be changed.

when printed I get:

    Starting Balance: $1000.00
    Annual Interest Rate: 0.05
    Monthly Payment: $120.00

But i need it to stop rounding the Annual Interest Rate as it is supposed to be .055. Thanks for any help ahead of time!

4Percent
  • 123
  • 1
  • 1
  • 5

1 Answers1

0

So remember the current precision, change it, then restore the original precision.
In code that would be something like:

auto const   precBefore  = std::cout.precision();
std::cout << std::setprecision(digitsAfterDecimalCount) << val;
std::cout << std::setprecision(precBefore);