Search This Blog

Tuesday, 22 January 2013

Number Formatting In XML


Number Formatting

Number Formatting

XML Publisher supports two methods for specifying the number format:
·         Microsoft Word’s Native number format mask.
Oracle’s format-number function.
·         Native XSL format-number function
Use only one of these methods. If the number format mask is specified using both methods, the data will be formatted twice, causing unexpected behavior. The group separator and the number separator will be set at runtime based on the template locale. This is applicable for both the Oracle format mask and the MS format mask.
To use the Oracle format mask or the Microsoft format mask, the numbers in your data source must be in a raw format, with no formatting applied (for example: 1000.00).

Using the Microsoft Number Format Mask

To format numeric values, use Microsoft Word’s field formatting features available from the Text Form Field Options dialog box. The following graphic displays an example:
To apply a number format to a form field:
1.    Open the Form Field Options dialog box for the placeholder field.
2.    Set the Type to Number.
3.    Select the appropriate Number format from the list of options.
The following table lists the supported Microsoft format mask definitions:
Symbol
Location
Meaning
0
Number
Digit. Each explicitly set 0 will appear, if no other number occupies the position.
Example:
Format mask: 00.0000
Data: 1.234
Display: 01.2340
#
Number
Digit. When set to #, only the incoming data is displayed.
Example:
Format mask: ##.####
Data: 1.234
Display: 1.234
.
Number
Determines the position of the decimal separator. The decimal separator symbol used will be determined at runtime based on template locale.
For example:
Format mask: #,##0.00
Data: 1234.56
Display for English locale: 1,234.56
Display for German locale: 1.234,56
,
Number
Determines the placement of the grouping separator. The grouping separator symbol used will be determined at runtime based on template locale.
For example:
Format mask: #,##0.00
Data: 1234.56
Display for English locale: 1,234.56
Display for German locale: 1.234,56
-
Number
Determines placement of minus sign for negative numbers.
E
Number
Separates mantissa and exponent in a scientific notation.
Example:
0.###E+0 plus sign always shown for positive numbers
0.###E-0 plus sign not shown for positive numbers
;
Subpattern boundary
Separates positive and negative subpatterns. See Note below.
%
Prefix or Suffix
Multiply by 100 and show as percentage
Prefix or Suffix
Used to quote special characters in a prefix or suffix.
Note: Sub pattern boundary: A pattern contains a positive and negative sub pattern, for example, "#,##0.00;(#,##0.00)". Each sub pattern has a prefix, numeric part, and suffix. The negative sub pattern is optional. If absent, the positive sub pattern prefixed with the localized minus sign ("-" in most locales) is used as the negative sub pattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there is an explicit negative sub pattern, it serves only to specify the negative prefix and suffix. The number of digits, minimal digits, and other characteristics are all the same as the positive pattern. That means that "#,##0.0#;(#)" produces precisely the same behavior as "#,##0.0#;(#,##0.0#)".
Example: -
Here we are using same RTF which we had used in IF STATEMENT.
RTF looks

Now we are going to format the number of Inv_Amt using the Microsoft Number format Mask which is shown below

for that give double click on Inv_Amt then we can see below window

In the above picture we can see there is one option as Type change it to Number which is show below



From the above picture we can see there is one option as Number format which has some number formats which is shown below

Here we have to give default number also which is shown below.
Select one of the above formats according to our requirement. Here we are selecting third option which is shown below

Click on ‘OK’

Now we have to publish the report

Click on Template Builder => Preview => HTML/PDF/Excel/RTF (any format).
We can get below output

From the above picture we can see the Number format of the Invoice_Amount what ever we had given in the Number format option.


Using the Oracle Format Mask:

To apply the Oracle format mask to a form field:
1.    Open the Form Field Options dialog box for the placeholder field.
2.    Set the Type to "Regular text".
3.    In the Form Field Help Text field, enter the mask definition according to the following example:
<?format-number:fieldname;’999G999D99’?>
where fieldname is the XML tag name of the data element you are formatting and 999G999D99 is the mask definition.
The following graphic shows an example Form Field Help Text dialog entry for the data element "empno":

Example: -
Here also we are going to take same RTF which we had taken in the IF STATEMENT which is shown below
Just give double click on Inv Amt then click on Add Help Text there we have to give XML format which is shown below

Click on ‘OK’

Now we have to publish the report

Click on Template Builder => Preview => HTML/PDF/Excel/RTF (any format).
We can get below output
From the above output we can see that Invoice_Amount is formatted into a specified format which we had mentioned in XML format.





The following table lists the supported Oracle number format mask symbols and their definitions:
Symbol
Meanings
0
Digit. Each explicitly set 0 will appear, if no other number occupies the position. Example: Format mask: 00.0000 Data: 1.234 Display: 01.2340
9
Digit. When set to 9, only the incoming data is displayed. Example: Format mask: 99.9999 Data: 1.234 Display: 1.234
C
Returns the ISO currency symbol in the specified position.
D
Determines the placement of the decimal separator. The decimal separator symbol used will be determined at runtime based on template locale. For example: Format mask: 9G999D99 Data: 1234.56 Display for English locale: 1,234.56 Display for German locale: 1.234,56
EEEE
Returns a value in scientific notation.
G
Determines the placement of the grouping (thousands) separator. The grouping separator symbol used will be determined at runtime based on template locale. For example: Format mask: 9G999D99 Data: 1234.56 Display for English locale: 1,234.56 Display for German locale: 1.234,56
L
Returns the local currency symbol in the specified position.
MI
Displays negative value with a trailing "-".
PR
Displays negative value enclosed by <>
PT
Displays negative value enclosed by ()
S (before number)
Displays positive value with a leading "+" and negative values with a leading "-"
S (after number)
Displays positive value with a trailing "+" and negative value with a trailing "-"

No comments:

Post a Comment