Home Segments Index Top Previous Next

539: Mainline

Alternatively, you can display handsome floating-point numbers, in columns, by including a field width, a period, and the number of digits that you want to appear to the right of the decimal point. Consider, for example, the following display statement:

              *-- Field width is 8 
              v 
printf ("%-6s%8.2f\n", "Food", 4700.1287); 
                ^ 
                *-- Two digits to appear after the decimal point 

The result is as follows:

Food   4700.12 

Note that the number displayed is truncated, rather than rounded.