Format - Numbers
Category : Technical Examples
Docmosis allows you to control how numbers are displayed in the finished document.
For example: the raw data may have numbers like: 1234.5.
Using the built-in function numFormat the number can be formatted so that it looks like this: $1,234.50.
This example explained
It is best to view the TEMPLATE and OUTPUT files side-by-side to understand the formatting that has been applied.
The function numFormat requires two parameters:
numFormat ( value, format )
The first is the value to be formatted and the second is a format string that describes the format to be applied.
The value can be taken directly from the data or the result of a calculation.
The format string should be enclosed in single quotes.
Here is an example of a format string: '$#,###.00'
The format string can contain:
# (hash) - represents any digit. If the # appears on the right of the decimal then a digit will only be shown if it is not zero. So trailing zeroes are not shown.
0 (zero) - represents any digit. A digit will always be shown. The result will be padded with leading or trailing zeroes as needed.
. (decimal point) - if a decimal point is present in the format string then the desired number of digits after the decimal point can be described using a # or 0. The number of digits before the point will expand to match the value being formatted.
, (comma) - this is most commonly used as the thousands separator. If a , (comma) appears in the format string, then the number of digits between the , (comma) and the . (decimal point) will be repeated in blocks. Most common is 3 digits.
% (percent) - if a percent character appears in the format then the value will be interpreted as a percentage, ie. the value will be multiplied by 100, then the format will be applied to the result.
(other characters) - any other characters at that start or finish of the format string will also appear in the formatted result. This is useful for adding currency ($) at the start of a number or units of measurement for weight/distance/etc at the end of a number.