cancel
Showing results for 
Search instead for 
Did you mean: 

Question on an UDF

Former Member
0 Kudos

Hello al,

On XI 3.0, i've made in a graphical mapping the following thing :

field1 multiply by 100 then i use function ROUND on the result and finally i divide it by 100

And it works correctly.

But i would like to do in an UDF because there is a lot a mapping to modify and i prefer to copy the udf in each mapping.

I think this might be something like this :

a string

a*100

resultvalue(a).round

a/100

Am i near the good syntaxt, because my java is very bad !!

Thanks by advance

Edited by: Jean-Philippe PAIN on Jul 3, 2008 1:04 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Here is the code

float i =Float.parseFloat(a);

i = Math.round(i*100);

i = i/100;

return Float.toString(i);

Former Member
0 Kudos

Thank you all. It works.

Answers (2)

Answers (2)

Former Member
0 Kudos

Try something like this -

public String round2(String a,Container container){
double d;

d = Double.parseDouble(a);
d = d * 100.0;
d = Math.round(d);
d = d/100;
String result = Double.toString(d);

return result;

 }

Regards,

Riyaz

Former Member
0 Kudos

Hi,

There is a bug in xi standard function for round, divide & multiply. if you take your input string more than 6 char then it will return it worng value. If don't believe just test it!!

What u can do is for dividing by 10 use the below mentioned UDF.

if( ! a.equals(""))

{

BigDecimal bigA = new BigDecimal(a);

BigDecimal result = bigA.movePointLeft(2);

return result.toString();

}

return "000";

Do not froget to put Imports values as shown below:

java.math.BigDecimal;

Try your to test for big values like 12345678 then you can find whatever UDF you have applied is woking correct or not.

regards,

Sarvesh

Edited by: Sarvesh Singh on Jul 3, 2008 5:13 PM