on 07-03-2008 12:04 PM
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
Here is the code
float i =Float.parseFloat(a);
i = Math.round(i*100);
i = i/100;
return Float.toString(i);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.