on 01-08-2011 12:34 PM
Hi,
I have 3 source fields min, max,type and decimal place as target field
sample values will be like
min = 14.1 (decimal places = 1)
max = 14.123 (decimal places = 3)
type = 14.11 (decimal places = 2)
I want the maximum decimal count, in this case its 3 (14.123). So I need a UDF to count the no.decimals places and pass the highest decimal count value to target field
Thanks,
Varun
Hi Varun Reddy,
I have tested successfully below code. Please pay attention to method declaration.
public String Return_MaximumDecimalCount(String Min, String Max, String Type, Container container) throws StreamTransformationException
{
int iMinDecimalCount = 0;
int iMaxDecimalCount = 0;
int iTypeDecimalCount = 0;
int iMaximumDecimalCount = 0;
//Check number has decimal value. if it is there then, count number of digits after . (decimal). -1 subtracted from count as indexOf() method return array count
if(-1!=Min.indexOf("."))
iMinDecimalCount = Min.length() - Min.indexOf(".") - 1 ;
if(-1!=Max.indexOf("."))
iMaxDecimalCount = Max.length() - Max.indexOf(".") - 1 ;
if(-1!=Type.indexOf("."))
iTypeDecimalCount = Type.length() - Type.indexOf(".") - 1 ;
//Find maximum value among iMinDecimalCount, iMaxDecimalCount, iTypeDecimalCount
iMaximumDecimalCount = (iMinDecimalCount > iMaxDecimalCount) ? iMinDecimalCount : iMaxDecimalCount;
iMaximumDecimalCount = (iMaximumDecimalCount > iTypeDecimalCount) ? iMaximumDecimalCount : iTypeDecimalCount;
return iMaximumDecimalCount + "";
}
Regards,
Raghu_Vamsee
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.