cancel
Showing results for 
Search instead for 
Did you mean: 

how to get values after decimal point

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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;

}

Answers (1)

Answers (1)

Former Member
0 Kudos

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