cancel
Showing results for 
Search instead for 
Did you mean: 

decimal

Former Member
0 Kudos

Hi,

I have the following mapping requirement-

If the incomming value is 100.00 , it should be passed as 10000 with leading zeros as per the field length.

ie; if the field length is 8 and we are getting value 100.00 it should be passed as 00010000.Please suggest me how to do this.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

first mutiply by 100. u will get 10000.

write UDF.

in UDF, first String Length in our case 5. which is 3 less than 8 Field length...

in loop append 3 zero to the number so u will get 00010000

Answers (5)

Answers (5)

Former Member
0 Kudos

yeah..I got the solution.First I removed '.' as said by shri and then used the following UDF

//write your code here
 String temp = new String(String.valueOf(Integer.parseInt(a)));
 int temp1 = Integer.parseInt(b); 
for(int i = 0; (temp1 - a.length()) > i ; i++)
{
temp = "0" + temp;
}

return(temp);

Former Member
0 Kudos

Thanks for the suggestions.The udf is working fine.But I want to use the same udf for different fields.So instead of 8, I want to pass the second input to UDF as the max length of the field.The second input can be a constant value since I know the max length of the fields.Can anyone change the udf according to this,so that i can used for any field.

Former Member
0 Kudos
Thanks for the suggestions.The udf is working fine.But I want to use the same udf for different fields.So instead of 8, I want to pass the second input to UDF as the max length of the field.The second input can be a constant value since I know the max length of the fields.Can anyone change the udf according to this,so that i can used for any field..

amt is the Input Argument of the UDF.

length1 is the Second Arguement of the UDF.

amt = Integer.parseInt(amt) * 100; " to Convert decimal to Numberic Value.

int len = amt.length();

String result;

result = String.valueOf(amt); " to Convert Amt to String

for(int i = 0; i< ( length1 - len ) ; i++)

{

amt = "0" + amt;

}

return(amt);

Edited by: ragu r on Aug 21, 2008 10:32 AM

Edited by: ragu r on Aug 21, 2008 10:33 AM

Former Member
0 Kudos

Hi,

If you have seen the UDF code I had given, just

add one more input parameter as b

and pass the constant value for every field as per the max length.

In the Java code just instead of Red colored 8 add the below value

Integer.parse(b)

This will make the udf to be re-usable

source field -


> TestUDF -


> target field

Constant(max length) -


>

thanks

Swarup

Former Member
0 Kudos

amt is the Input Argument of the UDF.

amt = Integer.parseInt(amt) * 100; " to Convert decimal to Numberic Value.

int len = amt.length();

String result;

result = String.valueOf(amt); " to Convert Amt to String

for(int i = 0; i< ( 8 - len ) ; i++)

{

amt = "0" + amt;

}

return(amt);

Former Member
0 Kudos

Hi,

Please use below code

Source field ---> TestUDF ---> Target field

Udf Name -- > TestUDF

Cache Parameter ---> Value

String temp = new String(String.valueOf(Integer.parseInt(a) * 100));

for(int i = 0; (8 - a.length()) > i ; i++)

{

temp = "0" + temp;

}

return(temp);

In the above code just change the value i.e. Marked with red color "8". that will make you the total length and will do the padding accordingly.

Thanks

swarup

Edited by: Swarup Sawant on Aug 21, 2008 8:16 AM

Edited by: Swarup Sawant on Aug 21, 2008 8:16 AM

Former Member
0 Kudos

sorry raghu , Iam not good at java programming.Can you please suggest the UDF code that you have mentioned

Former Member
0 Kudos

Hi Nagarjuna,

If you know that the decimal point will be at fixed position only then you can do it without using any java function.

Just treat that input as a string and replace '.' by empty. i.e. just take out '.' from the string and add leading zeros.

This is simplest way.

Regards,

Shri