precision [C++ Reference]
Keywords: io,precision
Date: 2009-05-01T14:55:50-0700

## precision

Syntax:

        streamsize ostream::precision();
        streamsize ostream::precision(streamsize p);

The precision() function either sets or returns the current number of digits that is displayed for floating-point variables. For example, the following code sets the precision of the cout stream to 5:

         float num = 314.15926535;
         cout.precision( 5 );
         cout << num;

This code displays the following output:

         314.16

Related Topics: fill, width