Im tryna get my code (as seen bellow) to print both the variable "jax" with two decimal places, and the full value opf the variable "jax"

so the out put should be:

8712.65
8712.654


How do i do this?

#include <iostream>
#include <iomanip>
using namespace std;

int main()

{
    
double jax=8712.654;

  //first output
 cout<<setprecision(2)<<fixed;   
 cout<<jax<<endl<<endl;

 //second output
 cout<<jax<<endl<<endl;

 system("pause");   
}

The precision of a stream persists after the call even if you use the manipulator. You can save the old value though, and reset it to what it was before:

streamsize old = cout.precision(2);
  
cout<< fixed << jax <<'\n';
cout<< setprecision(old) << jax <<'\n';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.