There are essentially four formatting parameters available. They are listed in the following table:
Parameter |
Use |
Fill/Alignment |
Used in conjunction with the Width parameter. Essentially, this will add extra characters if the output is smaller than the width. |
Sign/#/0 |
Flags for the formatter being used:
|
Width |
Specifies how the output should be represented. For example, if you have a float calculation that has to be outputted to four decimal places, and the result only comes to two decimal places, the width formatter (in conjunction with the fill formatting parameter) will create the required filled output. |
Precision |
For anything non-numeric, the precision is the maximum width. For example, if you have a maximum width of five and a string containing eight characters, it will be truncated after five characters. It is ignored for integers. For floating point types, it indicates the number of decimal points after the point:
|
Examples of all of these formatters are in the source code examples for this chapter.