cancel
Showing results for 
Search instead for 
Did you mean: 

how to replace formatNumber standard function with udf?

Former Member
0 Kudos

Hi Expert,

Currently I am using formatNumber standard function to create 18 digits number, but its failing when alpha numeric comes as input. now Can you please some udf to handle alphanumeric input and required to 18 digits output. if input length less than 18 digits, then zeros should be padded. Please suggest if it is possible thru graphical.

Please provide the udf earliest. thanks in advance.

Thanks,

chandar

Accepted Solutions (0)

Answers (3)

Answers (3)

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi chandra,

If your query has been answered, then can you please  close this thread.

former_member312864
Active Participant
0 Kudos

could you please provide sample input value and expected output

vinaymittal
Contributor
0 Kudos

use this

run this udf as all values of a context

String str = field[0];

    if(str.length()<18)

    {

   

    try{

    Double.parseDouble(str);

    for(int i=str.length();i<18;i++)

        str = "0"+str;

      result.addValue(str);   

    }catch(Exception e)

    {

    result.addValue(str);

   

}

}

    else

    result.addValue(str);   

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Chandra,

Try with the below udf:

if(input[0].length()>=18)

     result.addValue(input[0]);

else if(input[0].matches("[0-9]+"))

{

        String res="";

     for(int i=0;i<(18-input[0].length());i++)

            res=res+"0";

    res = res + input[0];

     result.addValue(res);

}

else

    result.addValue(input[0]);

If the input is a alphanumberic, then we are not padding any zeroes as the prefix.