cancel
Showing results for 
Search instead for 
Did you mean: 

Add Decimal point and leading zeroes after mapping

Former Member
0 Kudos

Hi Guys,

In the message mapping, UDF has to accept an input string and add leading zeroes and a decimal point before the last four decimals. The length of the string after mapping should be 14. The incoming field format is an integer.

eg., 234000 should be convereted to 000000023.4000 and 12 should be converted to 000000000.1200

UDF COde i used :

String str = Input; // input is the incoming field

int len = Input.length();

String str1,str2 = "";

for(int i=0;i<(Integer.parseInt(Length)-len);i++)

{

str = "0"+ str;

break;

}

str1 = str.substring(0,9);

str2 = str.substring(9,4);

str = str1"."str2;

return str;

RuntimeException:[java.lang.StringIndexOutOfBoundsException: String index out of range: -5] in class

Please provide your comments,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Vuppala,

Create a value udf with one input argument 'a' and name the function as createdecimal. Add this code:

Imports: java.*;

public String createdecimal(String a,Container container)

//write your code here

if (a.length() > 4)

{String str = a.substring(0, a.length()-4);

String res=a.substring(a.length()-4);

return str + "." + res;}

else

return "" + "." + a;

Then you map like this:

Source field --> createdecimal udf --> formatnum (double click and put 000000000.0000) --> target.

So if input is 234000 you have output as 000000023.4000

and if input is 12 you have output as 000000000.1200

and if input is 1234 you ahve output as 000000000.1234

Regards,

---Satish

Answers (0)