Home > Backend Development > C++ > How to Prevent C cout from Displaying Numbers in Scientific Notation?

How to Prevent C cout from Displaying Numbers in Scientific Notation?

Barbara Streisand
Release: 2024-10-27 06:50:29
Original
951 people have browsed it

How to Prevent C   cout from Displaying Numbers in Scientific Notation?

How to Disable Scientific Notation in C cout

When displaying double-precision floating-point numbers using cout in C , you may encounter scientific notation, which uses exponents to represent large or small numbers. This can make the output difficult to read. To disable scientific notation and display exact numbers, follow these steps:

Use the std::fixed stream manipulator. This manipulator instructs cout to use fixed-point notation, which represents numbers as decimals. The stream manipulator is used as follows:

<code class="cpp">cout << fixed << "Bas ana: " << x << "\tSon faiz: " << t << "\tSon ana: " << x + t << endl;</code>
Copy after login

In this example:

  • fixed disables scientific notation.
  • x is the initial principal amount.
  • t is the interest earned.
  • x t is the final amount.

By using std::fixed, the output will display exact numbers without scientific notation:

Bas ana: 3284.78       Son faiz: 1784.78       Son ana: 5069.55
Bas ana: 7193.17       Son faiz: 3908.4        Son ana: 11101.6
Bas ana: 15752        Son faiz: 8558.8        Son ana: 24310.8
Bas ana: 34494.5       Son faiz: 18742.5       Son ana: 53237
Bas ana: 75537.8       Son faiz: 41043.3       Son ana: 116581
Bas ana: 165417       Son faiz: 89878.7       Son ana: 255295
Bas ana: 362238       Son faiz: 196821        Son ana: 559059
Bas ana: 793246       Son faiz: 431009        Son ana: 1224255
Bas ana: 1737093       Son faiz: 943845        Son ana: 2680938
Bas ana: 3803973       Son faiz: 2066883       Son ana: 5870856
Copy after login

The above is the detailed content of How to Prevent C cout from Displaying Numbers in Scientific Notation?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template