cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to set the decimal places to the maximum amount of decimal places.

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

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

Answers (0)