c language floating-point input and output

Precision floating point number in C language to two decimal places of the statement is as follows

1

2

double a=2.0;

printf ("%.2f", a);//其中.2指明两位小数

 

Description: The% 9.2f 

Output field indicates a width of the float 9, which is 2 decimal places, 6 integer bits, if the default is a wide field 9 for the actual number of bits

Specifier

% D decimal signed integer

Decimal% u unsigned integer

% F float

% S string

% C single character

% P value pointer

Floating-point exponential% e

% X,% X unsigned integer expressed in hexadecimal

% O unsigned integer in octal representation

% G output from the output values ​​of the small length in accordance with the% f% e, or output mode type

% P output address character

% lu 32 bit unsigned integer

% llu 64 bit unsigned integer

Example:

main ()
{
a float A;
Scanf ( "% F", & A);
the printf (. "%. 2F", A); // output two decimal floating-point number.
}

Published 34 original articles · won praise 6 · views 4780

Guess you like

Origin blog.csdn.net/qq_42712280/article/details/93592657