on 12-24-2008 4:27 AM
hi,
I am getting model node filled up through bapi...which is having amount as one of the field type char. In component controller , in one of the method i am loop through that node and summing up amount, by converting into float and at last i store that total amount to context attribute named TOTAL type float.
what my problem is , if i am having 3 rows in table having amount 1000, 2000 , & 3000.45 like this in char format so while looping i convert it into float and add this to temporary varible called total type float. and then i assign total variable to context attribute TOTAL_CONT type float.
for(int i=0;i<wdContext.nodeItem_det().size();i++)
{
total = total+Float.valueOf(wdContext.currentItem_detElement().getAmount()).floatValue();
}
wdContext.currentContextElement().setTotal_cont(total);
so first time total is having 1000.0 , second time it is having 3000.0 and third time its having 6000.45 but at last when it set up to context attribute Total_cont , and comes to screen it shows 6000.4503..
i dont understand from its having 03 at last.
please sort it out..
thanks
saurin shah
solved
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what is 6000.4503..??? is same output you are getting?
the code posted seems okay. you can refer the modified code below; both will work
for(int i=0, total = 0; i<wdContext.nodeItem_det().size(); i++)
{
total = total+ (Float.valueOf( wdContext.nodeItem_det().getItem_detElementAt( i).getAmount())).floatValue();
}
wdContext.currentContextElement().setTotal_cont(total);
Next is to represent the attribute Total_cont
1. Create a Simple Type under Dictionaries
2. At Definition tab, select Built-in Type as float
3. go to Representation tab, specify External Representation Format as your desired format # stands for any number (example : ####.00)
4. change Total_cont attribute type to created simple type.
NikhiL
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Saurin,
Try printing out the value of Total just after the for loop and before you assign it to the context attribute.
If you get what you actually wanted, then check the properties of your context attribute.
i.e Try changing the type of your attribute to decimal/double/long and then check whether you get the desired result.
I guess it is printing that value you mentioned 6000.4503 as it is taking the exponentiation varaible e into consideration.
Regards
Kishan
Edited by: kishan chandranna on Dec 24, 2008 5:52 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.