C language: Output real numbers with%f, only 6 decimal places and the number of valid digits for float type data

Source: Internet
Author: User

1. Using%f to output real numbers, only 6 decimal places can be obtained.

Program:

#include <stdio.h>

int Main ()

{

Double A = 1.0;

printf ("%f\n", A/3);

return 0;

}

Results:

0.333333

Please press any key to continue ...

The number of significant digits of the 2.float type data.

Program:

#include <stdio.h>

int Main ()

{

float A;

A = 10000/3.0;

printf ("%f\n", a);

return 0;

}

Results:

3333.333252

Please press any key to continue ...

Note: Since the float type data has only 6 valid digits, the program starts from the seventh position on the left, and the following numbers are not guaranteed to be absolutely correct.


This article is from the "Rock Owl" blog, please be sure to keep this source http://10742111.blog.51cto.com/10732111/1718370

C language: Output real numbers with%f, only 6 decimal places and the number of valid digits for float type data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.