Hi just wanted to know how to set the number of zeroes after the decimal for the double data type.

for example

double z=3;

court<<z<<endl;

gives no zeroes after decimal.

Thanks in advance

Hi just wanted to know how to set the number of zeroes after the decimal for the double data type.

for example

double z=3;

court<<z<<endl;

gives no zeroes after decimal.

Thanks in advance

Setprecision when used along with ‘fixed’ provides precision to floating point numbers correct to decimal numbers mentioned in the brackets of the setprecison.

Try giving output like this:

cout<<fixed<<setprecision(6)<<z<<endl

1 Like

Can also use printf("%.3f",z) to print correct to 3 decimal places. If z is 23.34 it prints 23.340

@bal_95 …hmm I knew that I was looking for some clarity for the setprecision( ) function … But thanks anyways …