on 02-08-2011 2:12 PM
Hi,
source value is 12345.678 i wana the target side in 12345 in field and 678 in one field.
the source value its not fixed before decimal point value pass to one field and after decimal point value pass to other field
please help to me how to do this one.
Hi
Create two UDF ... one for whole number and second one for decimal. Tested the below code and works
Example
public String wholeNumber(String number,Container container) throws StreamTransformationException{
String wholenumber="";
if(number!=null && number!=""){
int index = number.indexOf(".");
wholeNum = number.substring(0,index);
}
return wholenumber;
}
public String decimal(String number,Container container) throws StreamTransformationException{
String decimal="";
if(number!=null && number!=""){
int index = number.indexOf(".");
decimal = number.substring(index+1);
}
return decimal;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Swathip,
You dont need to create 2 UDFs. You just need to create 1 simple UDF which takes one string array as input as usual and it has 2 Resultlist outputs. You need to map this 2 outputs from the UDF to the respective 2 target side fields where the values are to be mapped, one containing the portion before the decimal, and one after the decimal.
I HAVE TESTED THE UDF AND IT WORKS ABSOLUTELY FINE.
THE CODE FOR THE UDF IS AS FOLLOWS:
public void sepDec(String[] num,ResultList wholeNum,ResultList afterDec,Container c)
{
String part1=null; // Stores the part before the decimal point
String part2=null; //Stores the part after the decimal point
if(num[0]!=null && num[0]!=""){
int index = num[0].indexOf(".");
part1 = num[0].substring(0,index);
part2=num[0].substring(index+1, num[0].length());
}
wholeNum.addValue(part1);
afterDec.addValue(part2);
}
THIS UDF IS A CLASSIC EXAMPLE WHERE AN UDF HAS 2 OUTPUTS, WHICH IS VERY RARELY SEEN BUT VERY MUCH CORRECT
PLEASE LET ME KNOW IF THIS CODE WAS HELPFUL TO YOU
CHEERS,
BISWAJIT
Edited by: 007biswa on Feb 8, 2011 5:02 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.