Home Segments Index Top Previous Next

702: Mainline

The e specification is for displaying 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 %e x\n", 27182.8); printf ("x %e x\n", -0.000271828); 
printf ("Using E produces an upper-case E, as in x %E x.\n", 27182.8); 
--- 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 %.2e x\n", 27182.8); printf ("x %.2e x\n", -0.000271828); 
--- Result --- 
x 2.72e+04 x 
x -2.72e-04 x 

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

printf ("x %10.2e x\n", 27182.8); 
printf ("x %10.2e x\n", -0.000271828); 
--- 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 %10e x\n", 27182.8); printf ("x %10e x\n", -0.000271828); 
--- Result --- 
x 2.718280e+04 x 
x -2.718280e-04 x 

Display with spaces, on the right, if necessary:

printf ("x %-10.2e x\n", 27182.8); 
printf ("x %-10.2e x\n", -0.000271828); 
--- Result --- 
x 2.72e+04   x 
x -2.72e-04  x 

Always include sign:

printf ("x %+10.2e x\n", 27182.8); 
printf ("x %+10.2e x\n", -0.000271828); 
--- Result --- 
x  +2.72e+04 x 
x  -2.72e-04 x