Skip to content

Instantly share code, notes, and snippets.

@SriniBlog
Created December 23, 2015 15:33
Show Gist options
  • Save SriniBlog/15904dd7132e50750e97 to your computer and use it in GitHub Desktop.
Save SriniBlog/15904dd7132e50750e97 to your computer and use it in GitHub Desktop.
This UDF will add the leading zero to the number based on the length of the field.
public String addLeadingZero(String FieldValue, String Zeros, Container container) throws StreamTransformationException{
String newFieldValue = "";
String newZeros = "0";
try{
//Convert Zero to int iZeros
int iZeros = Integer.parseInt(Zeros);
//Check how Zeros to add
iZeros = iZeros-FieldValue.length();
// If Zeros length is less than actual FieldValue length
if (iZeros <= 0 ) return FieldValue;
//Run the loop to Create Zeros String
for(int i=0; i< iZeros-1; i++){
newZeros = newZeros + "0";
}
// Append Zero String to the actual value
newFieldValue = newZeros + FieldValue;
}catch(Exception ee){
newFieldValue = FieldValue;
}
return newFieldValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment