What is the double output format?

醉折花枝作酒筹
Release: 2023-01-07 11:45:53
Original
39274 people have browsed it

The regular output of double type is "%lf", but by default, double type outputs 6 digits after the decimal point. We usually need to reduce its length after the decimal point. You can use the form "%m.nlf", where m and n are both positive integers.

What is the double output format?

The operating environment of this tutorial: Windows 7 system, C 17 version, Dell G3 computer.

The double (double-precision floating point) type is one of the basic types of the C language. It occupies 8 bytes and can be expressed up to 1.7*10^308. Under normal circumstances, it can meet the needs of the program.

The regular output of double is %lf (note that the float type output is %f) For example: define double a = 1.0; use printf("%lf",a);

but the double type By default, the output is 6 digits after the decimal point, and we usually want to reduce its length after the decimal point. You can use the form "%m.nlf", where m and n are both positive integers. m means that the output floating-point data occupies m bits. If the actual length is not equal to m, it will be output according to the actual length. n means the number of decimal points in the output. Therefore, m can actually be ignored, just replace it with 0 or leave it alone!

For example, the above output is: 1.000000 (by default)

If the output format is changed to "%0.0lf" or "%4.0lf", the output will be 1 (m! = actual length )

By the way, the C language does not support the long long int type in VC, but it is supported under Linux. long long int also occupies 8 bytes

Recommended tutorial: "C#"

The above is the detailed content of What is the double output format?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!