上QQ阅读APP看书,第一时间看更新
How it works...
The TEMPLATE constant contains three columns, each one properly named (REVENUE, PROFIT, PERCENT). This makes it more explicit and straightforward to apply the template on the format call.
After the name of the parameter, there's a colon that separates the format definition. Note that all inside the curly brackets. In all columns, the format specification sets the width to seven characters and aligns the values to the right with the > symbol:
- Revenue adds a thousands separator with the , symbol—[{revenue:>7,}].
- Profit adds a + sign for positive values. A - for negatives is added automatically—[{profit:>+7}].
- Percent displays a percent value, with a precision of two decimal places—[{percent:>7.2%}]. This is done through 0.2 (precision) and adding a % symbol for the percentage.