VOOZH about

URL: https://www.geeksforgeeks.org/cpp/floating-point-default-print-format/

⇱ Floating Point Default Print Format in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Floating Point Default Print Format in C++

Last Updated : 29 Jan, 2026

Floating-point output formatting in C++ controls the representation of real numbers, including precision, notation (fixed/scientific), width, and alignment during stream insertion.

  • By default, C++ prints floating values with limited precision (6 significant digits), balancing readability and accuracy.
  • Manipulators like setprecision, fixed, and scientific allow you to change the display format.

Output
1.23457
1.23457e+08

Floating-Point Output Behaviors:

1. No Trailing Zeros:

By default, floating-point numbers are printed without trailing zeros, providing a compact and readable output, though manual formatting may be needed for consistent width.


Output
3.14
5

Explanation: The output is 3.14 and 5 because C++ omits unnecessary trailing zeros when printing floating-point numbers by default.

2. Precision Refers to Total Digits:

Precision in floating-point printing defines the total number of significant digits, not just the digits after the decimal point. This behavior emphasizes the value's overall accuracy rather than merely focusing on its decimal representation.


Output
123.457
0.000123456

Explanation: C++ uses a default precision of 6 significant digits, so 123.456789 is rounded to 123.457 while 0.000123456 is printed fully until six meaningful digits are reached.

3. Switching to Power Format:

If the integral part of a floating-point number exceeds the default precision (6 significant digits), C++ automatically switches to scientific notation to preserve significant digits. This behavior can be controlled using stream manipulators like fixed, setprecision, or scientific.


Output
1.23457e+06
0.000123456

Explanation: When a number exceeds the default precision of 6 significant digits, it is automatically displayed in scientific (power) notation to keep the output compact and precise.

Comment
Article Tags:
Article Tags: