Home Segments Index Top Previous Next

795: Mainline

The e specification is for printing floating-point numbers in scientific notation. Note that xs are included in the printf statement to clarify the placement of padding characters:

Display float or double:

printf ("x  
printf ("Using E produces an upper-case E, as in x  
--- Result --- 
x 2.718280e+04 x 
x -2.718280e-04 x 
Using E produces an upper-case E, as in x 2.718280E+04 x. 

Display with two digits following the decimal point:

printf ("x  
--- Result --- 
x 2.72e+04 x 
x -2.72e-04 x 

Display with spaces, if necessary, to fill a 10-character field:

printf ("x  
printf ("x  
--- Result --- 
x   2.72e+04 x 
x  -2.72e-04 x 

Display with spaces, if necessary, to fill a 10-character field; if more than 10 characters are involved, display them all anyway:

printf ("x  
--- Result --- 
x 2.718280e+04 x 
x -2.718280e-04 x 

Display with spaces, on the right, if necessary:

printf ("x  
printf ("x  
--- Result --- 
x 2.72e+04   x 
x -2.72e-04  x 

Always include sign:

printf ("x  
printf ("x  
--- Result --- 
x  +2.72e+04 x 
x  -2.72e-04 x 

Always include sign and pad on the right:

printf ("x  
printf ("x  
--- Result --- 
x +2.72e+04  x 
x -2.72e-04  x