cancel
Showing results for 
Search instead for 
Did you mean: 

Fill with zeros on the left side if length is not 10

Former Member
0 Kudos
144

hi Team,

I have a question i think an UDF must be used for this requirement.

that is.

" Length of this field should be 10 characters. If don't fill with zeros on the left."

Can any one help me in this plz.

Thanks & Regards,

vishnu

Accepted Solutions (0)

Answers (8)

Answers (8)

Former Member
0 Kudos

Hi Vishnu,

U can use this:

int str_len;

int yes_no = 0;

int count;

char[] b = new char[10];

str_len = a.length();

if (str_len < 10)

{

a.getChars(0,str_len,b, 0);

for (int i=0;i<str_len;i++)

{

if (b<i> != '0' && b<i> != '1' && b<i> != '2' && b<i> != '3' && b<i> != '4' && b<i> != '5' && b<i> != '6' && b<i> != '7' && b<i> != '8' && b<i> != '9')

{

yes_no = 1;

continue;

}

}

if (yes_no != 1)

{

count = 10-str_len;

for (int j=0;j<count;j++)

{

a=0+a;

}

return a;

}

else

return a;

}

else

return a;

Thanks,

Sudhansu

Ps: Provide points for helpful answers

Former Member
0 Kudos

Hi Vishnu,

I am writing a UDF for this.

String res = "" ;

int LengthString = a.length();

if (!a.equals(""))

res = res + a ;

for(int i=LengthString; i< 10; i++)

{

res = 0+res ;

}

return res;

This will check the length of your source field and insert zeroes whenever the length is less than 10.

regards,

Ramya Shenoy.

note:This udf works..give me points .

Edited by: Ramya Shenoy on Aug 27, 2009 11:19 AM

Former Member
0 Kudos

Other Option



   //write your code here
 int vLength = Integer.parseInt(pLength);
String value = "";
 if (pValue.length() <= vLength){
       int missing =  vLength - pValue.length();
        for (int i = 0 ; i < missing ; i++)
            value+="0";
        value=value + pValue;
}else{
  value = pValue;
}
return value;


Former Member
0 Kudos

Hi Vishnu,

If the Input is always number then you can use FormatNum standard function. But input value contains single character, that standard function doesn't support.

So, use this UDF.


    for(int i=0;i<10 - a.length();i++)
         {
             res = res + "0";
         }
		   
      res = res.concat(a);
return res;

I hope, it will work fine.

regards

Vijaykumar

Former Member
0 Kudos

Hi ,

you can achive this using the standard function FORMAT NUM

Regards,

Jude

Former Member
0 Kudos

Hi Vishnu,

If the input is always a number then you can use formatnum with 10 zeros. But if any one the record is having text instead of number then formatnum will not work. Then you need udf. Check this thread for the udf:

Regards,

---Satish

jyothi_anagani
Active Contributor
0 Kudos

Hi Vishnu,

No need of UDF...

Map like this...

input------->formatNumber[0000000000]---->output

provide 10 '0's there..

It will automatcally add 0's on left hand side if that is not having 10 digits...

formatNumber is a standard function in Arthematic functions in Graphical mapping....

Thanks.

santhosh_kumarv
Active Contributor
0 Kudos

try this..

String outVal = "0000000000" + inVal.trim();
outVal = outVal.substring(inVal.length() - 10);
return outVal

inVal is the input to the UDF.

~SaNv...