cancel
Showing results for 
Search instead for 
Did you mean: 

problem with the Right align UDF

Former Member
0 Kudos

Hi there,

Can somebody please tell me how and what is the solution of this simple case?

Example

1234567890.12

876.11

456789881.34

The above values are present in 1 field not in 2 fields.

the input contains the decimal values as well i.e. field1 = 1234.32

I need to generate an output with fixed length of 17 char which contains 2 decimal and 15 values and if there is no values than I need to add the spaces before the numbers not after the number.

xxxxxxxxxx12345.12

xxxxxxxx3456789.45

where xx represent spaces.

I tried different functions such as formatnumber, substring, indexOf but none of them work according to the requirement.

I believe the only way is to do it via udf so can somebody please help me.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

U can write UDF and for loop first check the length of the input field using .length java function.

Use for loop and loop till 18 character I am considering "." as one character and append space

chirag

Former Member
0 Kudos

Hi chirag,

Thanks for your reply.

will it be possible you can write a code for me because I don't know much about the java that's why I am struggling.

I know it's a very simple and easy task but unfortunately because of no java experience i am stuck.

I hope you will help me.

Thanks,

Former Member
0 Kudos

u can refer the below link:-

http://www.roseindia.net/java/beginners/length.shtml

use for loop and append space with the number.

Search on google u wil get help.

chirag

Shabarish_Nair
Active Contributor
0 Kudos

try;

int len = 17 ;

//var1 is the input to the UDF

StringBuffer sBuf= new StringBuffer(var1);

while (sBuf.length() < len) {

sBuf.insert(0,' ');

}

return(sBuf.toString());

Former Member
0 Kudos

You are Genius Shabarish.

Thank you so much for solving my problem.

The code is working perfectly.

Answers (0)