on 03-03-2010 1:57 PM
Hi all,
My requirement is, if we get a source value with 12.1 we need to convert this to 12.10.
If i get 0 from source i need to get 0 as output.
so basically i need to find out of decimat dot (.) exists or not and if itdoesnot exists then pas the value as it is.
if decimal exists then check of the lenght is 2 after decimal, its 2 send the value as it is...if its 1 then append 0 and pass the value.
How do i achieve it using UDF or Graphical mapping.
Thanks & Regards,
Karthick
Edited by: karthick Lakkaraju on Mar 3, 2010 7:29 PM
Hi Karthick,
You can do like this for your logic. First lets find whether you have a decimal in input. If no then pass as it is. If yes then we will use two udfs one for getting the value before decimal and one after getting the value after decimal. Once we get the value after decimal lets check the length and if it is more than two then substring the input. Else we will multiply by 10 which will give you the resulted value. After this we will concat both the before decimal value and afte decimal value.
Map as shown in this picture:
http://gickr.com/results4/anim_a2beb86b-c332-1f14-5981-09a5c0011208.gif
The code for the two udfs are:
udf1: Create a value udf with one input arguemnt a and name it as beforedecimal. Then add this code:
Imports: java.*;
int i = a.indexOf(".");
a = a.substring(0,i);
return(a);
udf2: Create a value udf with one input arguemnt a and name it as afterdecimalvalue. Then add this code:
Imports: java.*;
int k = a.length();
int i = a.indexOf(".");
i = i +1;
a = a.substring(i,k);
return(a);
Then you should get as expected. I tested withall the test cases you mentioned and it works fine for me.
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Source --> UDF --> Target
UDF code will be:
int len = value.lastIndexOf("."); //to check position of decimal value
value = value.substring(len+1);
if (value.length() < 2){
value = value + "0";
return value;
}
The above UDF code may require some modification!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
do as follows
1) Use the IndexOf function in string functions to check the occurance of a .(dot) in the input field)
2) If the indexOf returns a value greater than 0, then use formatNumber function with property as #######.##
3) In the else condition, pass the input value directly.
Regards,
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you changed the req:(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.