Add leading zeros to numbers on reports


 Product(s):Promis.e, Bentley Substation
 Version(s):through 08.11.13.73
 Environment:N/A
 Area:Template Management
 Subarea:Report Template Designer

Background

This document describes how to force numbers to be displayed as a specified number of digits on a report by using a script in the report template. The script adds the necessary amount of leading zeros to the numbers.

Steps to Accomplish

Copy the following script and paste it as the contents of the [[Before Print scripts for report templates|BeforePrint script]] for the table cell or label that displays the number:


int number;
string value = (sender as XRLabel).Text;

bool result = Int32.TryParse(value, out number);
if (result)
{
   (sender as XRLabel).Text = number.ToString("D3");
}
else
{
   (sender as XRLabel).Text = value;
}


Notes:

The "D3" argument in the script sets the number of digits to 3.  Change the 3 to the desired number of digits.

If the number is not an integer value it will be displayed in its original format.

External Links

How to: Pad a Number with Leading Zeros

 Original Author:John Spathaky

Keywords: text on drawing, losing, drop, wire number, page number
P/S: 68481, 500000086444