Created
December 23, 2015 15:33
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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