cancel
Showing results for 
Search instead for 
Did you mean: 

Padding Zeros

Former Member
0 Kudos

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 .

Accepted Solutions (1)

Accepted Solutions (1)

former_member859847
Active Contributor
0 Kudos

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 Kudos

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

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

There can be two ways to do this.

Eithere you do it in xslt itself or just use the Arithmetic function -


> FormatNum as shown below.

Source -


> xsltmapping -


> FormatNum -


> Target

OR

Source -


> FormatNum -


> xsltmapping -


> Target

Double click on FormatNum and enter 10 zero's in the upper input box.

Regards,

Sarvesh

Former Member
0 Kudos

HI,

Have u tried <xsl:number format="000000000" >?

Thanks,

Tuhin