Calc Format Number in DIAL

The calc.format_number function in DIAL specifies a pattern for the output of numbers, including the number of decimals and digits, and determines the thousandths separator.

Function Description

calc.format_number(value, format)

Returns a formatted number. The value argument is an expression that evaluates a number. The format argument is a string enclosed in quotation marks that specifies a pattern to use in formatting the number. The format string is equivalent to the pattern that is used in the java.text.Decimal Format class in Java. Each format has at least one pattern.

Pattern Syntax

A pattern consists of a positive pattern and an optional negative pattern, which is commonly referred to as a subpattern. Each positive pattern and a negative subpattern is separated by a semicolon (;).

positive pattern [';' negative pattern]

Each subpattern contains an integer and can optionally contain a prefix, a fraction, and a suffix, as shown by the following syntax:

[prefix] integer [ '.'  fraction] [suffix]
  • The prefix and suffix can contain any non-special characters such as currency symbols, parentheses, and percent (%). If % is used, the number is multiplied by 100 and shown as a percentage. To display a percent sign without performing the multiplication, enclose the sign in single quotation marks ('%').
  • The asterisk (*) character indicates one or more instances. When specifying more than one integer, use a comma (,) separator.
  • Integers can be:
  • '#'*
  • '0'*
  • '0'
  • Fractions can be:
  • '0'*
  • '#'*

Special Pattern Characters

Special pattern characters represent other characters, strings, or classes of characters. Unless otherwise noted, these characters must be contained in quotation marks ( " " ) if they are to appear in the prefix or suffix as literals.

Character Description
0 Placeholder for a digit. This character always appears as a digit.
# Place holder for a digit. This does not display if not needed.
- Negative sign
. Decimal separator for locale
, Grouping separator for locale (used in integer portion)
E Separates mantissa and exponent for exponential formats
% Multiplies by 100 and shows as a percentage

Keep the following points in mind:

  • If the value has more significant digits than the number of digits in the format fraction, the number is rounded up to the appropriate value—that is, if the number could be rounded to two numbers that are equidistant, the higher number is selected.
  • If the format is an invalid pattern, format_number returns "********".
  • When using cBases, if explicit formatting is not done in the DIAL script, any formatting specified in the Spectre Build or cPlan is used.

Calc Format Number Examples

The following examples demonstrate the usage of the calc.format_number function. Either calc.format_number or format_number can be specified.