Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

decimals problem after calculation

vinod_vemuru2
Active Contributor
0 Likes
599

Hi All,

I am facing an issue with decimals after calculation.

Below is my calculation.

l_sales_amt_round = lwa_post_data-cccur_sale +

( lwa_post_data-cccur_sale *

wa_post_data-taxper ).

Here lwa_post_data-cccur_sale has 2 decimals

wa_post_data-taxper has 3 decimals.

Result variable l_sales_amt_round of type f. ( Tried with TYPE P DECIMALS 3).

Is there any way to extract only the first 2 decimals into an amount field. I dont want this in character field.

eg: lwa_post_data-cccur_sale = 4854.00

wa_post_data-taxper = 0.175

Then l_sales_amt_round = 5.7034499999999998E+03

But when i move this to TYPE P DECIMALS 2 it is rounding to 5703.45.

But my requirement is to get 5703.44.

Is there any way to achieve this.

Thanks,

Vinod.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
558

Hi Vinod,

maybe the following code snippet is helpful:

data: result type p decimals 2,
result = round( val = l_sales_amt_round dec = 2 mode = CL_ABAP_MATH=>ROUND_DOWN ).

Best regards,

Andreas

3 REPLIES 3
Read only

Former Member
0 Likes
558

Isn't that what the DIV operand is for?

Check the online help for more info and examples, because I have never used it.

Kind regards, Rob Dielemans

Read only

Former Member
0 Likes
559

Hi Vinod,

maybe the following code snippet is helpful:

data: result type p decimals 2,
result = round( val = l_sales_amt_round dec = 2 mode = CL_ABAP_MATH=>ROUND_DOWN ).

Best regards,

Andreas

Read only

vinod_vemuru2
Active Contributor
0 Likes
558

Hi,

Thanks for the responce.

I have solved the problem on own as below.

l_sales_amt_round = ( lwa_post_data-cccur_sale *

wa_post_data-taxper ).

CLEAR l_tax_amt.

MOVE l_sales_amt_round TO l_tax_amt.

SHIFT l_tax_amt RIGHT.

SHIFT l_tax_amt RIGHT.

MOVE l_tax_amt TO l_sales_amt_round.

Here l_tax_amt is char field.

Thanks,

Vinod.