‎2007 May 18 9:02 PM
Hello friends,
Rounding issue.
Hello friends, I am having a problem with rounding issues.
Lets say I have 500 as quantity. Now I split 500 into three quantities. Lets say when I do the split it splits into 100.6, 100.6, 298.8.
So when I am rounding it becomes 101, 101, 299 and now the total is 501, and is different from available.
Can any one suggest how I can handle this issue? I want 500 even after the split.
Ster.
‎2007 May 18 9:57 PM
Hi,
Check this example...Try giving different values in v_menge & v_times..
You will get the split quantity in the internal table T_QTY.
DATA: t_qty TYPE STANDARD TABLE OF int4 WITH HEADER LINE.
DATA: v_menge TYPE menge_d.
DATA: v_times TYPE n.
DATA: v_sum TYPE int4.
v_menge = '200'. " Input quantity
v_times = 3. " Input times
t_qty = v_menge / v_times.
* Append the internal table with same quantity.
DO v_times TIMES.
APPEND t_qty.
ENDDO.
* Calculate the sum of the quantity in the internal table.
LOOP AT t_qty.
v_sum = t_qty + v_sum.
ENDLOOP.
* If the sum is greater adjust the difference in the last record
IF v_sum > v_menge.
v_sum = v_sum - v_menge.
READ TABLE t_qty INDEX v_times.
t_qty = t_qty - v_sum.
MODIFY t_qty INDEX v_times.
* If the sum is lesser add the difference in the last record.
ELSEIF v_sum < v_menge.
v_menge = v_menge - v_sum.
READ TABLE t_qty INDEX v_times.
t_qty = t_qty + v_menge.
MODIFY t_qty INDEX v_times.
ENDIF.
BREAK-POINT.
Thanks,
Naren
‎2007 May 18 9:04 PM
Hi Ster,
Try declaring the data type as Float.
Reward points if helpful.
Thanks
Aneesh.
‎2007 May 18 9:07 PM
‎2007 May 18 9:05 PM
are you using data type Packed ? if so try to use Float Data type.
‎2007 May 18 9:07 PM
Hi,
Please try this.
DATA: NUM1 TYPE F,
NUM2 TYPE I.
NUM1 = 500 / 3.
NUM1 = NUM1 * 3.
MOVE NUM1 TO NUM2.
WRITE:/ NUM1, NUM2.
Regards,
Ferry Lianto
‎2007 May 18 9:15 PM
Hi all,
let's see this example
Available: 200
200/3 = 66.6
first 2 round in normal way.
then it will be 67 + 67 = 134
for the 3rd one... if decimal is less than .5 then use CEIL to round OR if the decimal id greater that .5 then use FLOOR to round that.
so add 134+66 = 200
I think it will solve your problem
Thanks and Regards
Pavan Kothapalli
‎2007 May 18 9:38 PM
Thanks everyone for the suggestion.
Aneesh, Seshu.
the method you guys suggested works fine but the output comes with decimals. the output cane be decimals has to be full values with no decimals.
Pavan, how do i know the last record i will processing, because it can be split into 3 or 4 any number.
ANy more suggestions.
‎2007 May 18 9:46 PM
‎2007 May 18 9:48 PM
Move the decimal value to Intger field,now you will get no decimals.
‎2007 May 18 10:05 PM
Hi Ster,
Declare another variable as integer and at last when you r done with all the splitting and stuff, pass the output to this variable.
Reward points if useful.
Thanks
Aneesh.
‎2007 May 18 9:57 PM
Hi,
Check this example...Try giving different values in v_menge & v_times..
You will get the split quantity in the internal table T_QTY.
DATA: t_qty TYPE STANDARD TABLE OF int4 WITH HEADER LINE.
DATA: v_menge TYPE menge_d.
DATA: v_times TYPE n.
DATA: v_sum TYPE int4.
v_menge = '200'. " Input quantity
v_times = 3. " Input times
t_qty = v_menge / v_times.
* Append the internal table with same quantity.
DO v_times TIMES.
APPEND t_qty.
ENDDO.
* Calculate the sum of the quantity in the internal table.
LOOP AT t_qty.
v_sum = t_qty + v_sum.
ENDLOOP.
* If the sum is greater adjust the difference in the last record
IF v_sum > v_menge.
v_sum = v_sum - v_menge.
READ TABLE t_qty INDEX v_times.
t_qty = t_qty - v_sum.
MODIFY t_qty INDEX v_times.
* If the sum is lesser add the difference in the last record.
ELSEIF v_sum < v_menge.
v_menge = v_menge - v_sum.
READ TABLE t_qty INDEX v_times.
t_qty = t_qty + v_menge.
MODIFY t_qty INDEX v_times.
ENDIF.
BREAK-POINT.
Thanks,
Naren
‎2007 May 18 10:05 PM