cancel
Showing results for 
Search instead for 
Did you mean: 

Farmat number(UDF)

Former Member
0 Kudos
44

Hi Friends,

I aneed to use userdefined function for format number .If i get charecter i should pass the charecte as it is and if i get the value in the source then i have to format the number.Could you please give me the UDF program for this.

Thanks in advance,

Kalam.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

As you said you will also get characters in your string so in that case you can not use FormatNum function, so in order to suggest you UDF let us know how you want to format if it is numric value.

Regards,

Sarvesh

Former Member
0 Kudos

HI,

I have a requirement where if the value for a field comes as a blank or as character(non-integer), i want to pass the same value as it is.

If it is a number(Integer) then only i need to format it i.e. padding zeroes.

For Example : Material number is of type character, so it can be either number or character.

i want to add zeroes to Material number if it is only number. if it character or blank i have to leave it like that.

Regards,

Kalam.

prateek
Active Contributor
0 Kudos

Simply use UDF for this condition about finding whether sender fiels is numeric or not. The code below will return the integer if the number is in integer format else will return 0.

int i = 0;
try{	
Integer.parseInt(i);
return i;             
}	
catch(NumberFormatException e){
return "0";
}

After this UDF, you may use formatNum function.

Regards,

Prateek

SudhirT
Active Contributor
0 Kudos

Check this link for various ways of identifying the string if it is numeric or alphanumeric.

Also involve condition for blank string otherwise it'll throw exception.Then use the standard function formatNum.

Former Member
0 Kudos

> For Example : Material number is of type character, so it can be either number or character.

> i want to add zeroes to Material number if it is only number. if it character or blank i have to leave it like that.

Try this UDF..

int k = 0;
int i = 0;
try {
i = Integer.parseInt (a);
} catch (Exception E){
return a;
}

k = 18 - a.length();          // suppose material's std. length is 18
for( int j = 0 ; j < k; j ++)
{
a = "0" + a;
}
return a;

Regards,

Sarvesh

prateek
Active Contributor
0 Kudos

How exactly would you like to format the number? Can't you use standard formatNum function?

Regards,

Prateek