To get precision of n digits in decimal value.

First of all use the header #include<iomanip>

Write cout<<fixed;   ///// to get the same precision of zeros also in decimal points.

Then cout<<setprecision(n);   ----(A)

         cout<<variable;   //variable which you want with n decimal precision points.

Note: the value n should be in the decimal ranging of datatype. You can also use type casting to get more decimal point values.

Now all the values printed after the above statement A  will have the same precision.

In order to disable the precision use the statement cout.unsetf (ios::fixed);


Comments

Popular posts from this blog

First_Come_First_Serve CPU Scheduling

Reversing stack Method 2 !! (One Helper Stack only)

Populating Next Right Pointers in Each Node in O(1) space (without queue and level order)

Calculate factorial of large numbers !! (Using Arrays)

Multiplication of large numbers (Given in string format)

Left View of Binary Tree (Method 1 using recursion)

Check Bracket Sequence

Image Multiplication

Boundary Traversal of binary tree

BST to greater sum tree