on 02-18-2008 4:41 PM
Hi All,
I have a small doubt in floating number calculation in Mapping.
Actually i am geting a floating point number and calculating the SUM and generating the output. The input is of 2 decimal places(Ex: 26.02 and 26.03 ), but when it is adding all the values it is generating a three digit decimal number (Ex: 52.050003)
I dont know from where it is geting one extra number "2" in the output.
Please find the code for the same and let me know if i need to do something else to get ride of this.
**********************************************************************
//write your code here
float sum=0;
if(a != null && a.length > 0.00)
{
for ( int j =0; j<a.length;j++)
{
sum = sum + Float.parseFloat(a[j]);
}
result.addValue(String.valueOf(sum));
}
else
result.addValue("0");
***********************************************************************
Thanks in Advance,
JAY
Jay,
Please use the below code and let us know, if it helps.
BigDecimal sum= new BigDecimal("0");
BigDecimal bd;
if(a != null && a.length > 0.00)
{
for ( int j =0; j<a.length;j++)
{
bd=new BigDecimal(a[j]);
sum=sum.add(bd);
}
result.addValue(""+sum+"");
}
else
result.addValue("0");
in import section - java.math.*;
raj.
Edited by: Raj on Feb 18, 2008 11:11 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Raj U r a STAR...
It really solve my problem, and i just changed the code a little and passed all the value if it is of two dight after decimal and put that one inside the loop to get all the value.
if(count==0)
result.addValue(a<i>);
else
throw new RuntimeException("Values precisioned by more than 2 digits");
Once more thing can you please let me know from where i can find the java stuff that is required to generate the UDF in XI.
Warm Regards,
JAY
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I want to supress the whole message with generating the target.
Regards,
JAY
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jay,
Write this code and map the output to the root node of the target, let me know if it helps!
StringTokenizer st;
String temp;
int count=0;
for(int i=0;i<a.length;i++)
{
st= new StringTokenizer(a<i>,".");
st.nextToken();
temp=String.valueOf(st.nextToken());
if(temp.length()>2)
count+=1;
}
if(count==0)
result.addValue("");
else
throw new RuntimeException("Values precisioned by more than 2 digits");
raj.
Hi Patrick,
You are right,
Once we are geting 12.12 it should generate the output as 12.12
But if we are geting 12.123 then the souput should be SUPRESSED.
Hope you got it.
Regards,
JAY.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jay,
From your above code, I understood that you will have multiple values coming from the source,that's the reason you used Queue.Could you let us know, if you get the following data, what needs to be done.
for example,
<value>12.12</value>
<value>14.12</value>
<value>11.1234</value>
<value>13.12</value>
So you don't want only 11.1234 or u must suppress the whole mapping by not generating the target.
raj.
I need to supress the whole file, not the single document.
So in the output i should get as SUPRESS,
As a result the file should go into error and we should convey this to the business.
Regards,
JAY
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All/Raj,
I have to check the in-coming amount upto 2 decimal places only, if the incoming amount is more than 2 decimal places then it should get supressed.
Any Idea from ur side will of great help.
Regards,
JAY
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One question:
why are u using udf when you can do it simply by graphical Arithmatic functions?
Ranjit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot buddy..
This really solve my problem..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.