cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Padding Zeros

Former Member
0 Likes
513

Hi All,

I am using XSLT mapping.I want to get the field in the receiver side with the leading zeros.Source field: XSD :decimal and length is 10.If input is 12345, i have to get 0000012345.

Can anybody please solve the problem and guide me if u know .

View Entire Topic
former_member859847
Active Contributor
0 Likes

Hi,

use the user defind function with the following code.

while( inputField.length() < Integer.parseInt(totalLength))

{

inputField = 0 + inputField ;

}

return inputField;

warm regards

mahesh.

Former Member
0 Likes

Hi,

This UDF can also help you.

// pad a to this length if a is numeric

int targetLength = 40;

// determine if the material is numeric or alphanumeric

try {

// an exception is thrown if a is not an integer

Integer.parseInt(a);

// the material is numeric, proceed with formatting

// Create a buffer for the new string

StringBuffer buffer = new StringBuffer(targetLength);

// If it's already long enough, return the original string

if (a.length()>=targetLength) { return a; }

// Loop through and add zeros to the buffer

for (int q=0; q<targetLength-a.length();q++) { buffer.append("0"); }

// append the material

buffer.append(a);

// return the new result

return buffer.toString();

} catch (NumberFormatException e) {

// the material is alpha or non-integer, return the material unchanged

return a;

}

regards,

Anu Singhal