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

wrong result in simple computation

Former Member
0 Likes
1,675

Hi Gurus

need help, i have a requirement for computing in vat ,in calculator it seems correct but in abap the result is different. this weird scenario i encountered.

all variables are in type p decimals 2.

netwr = 249.38

kbetr = 50.00

i try 2 approach.

vat = (netwr * ( kbetr / 1000))

and

tmp_var = kbetr / 1000.

vat = netwr * tmp_var

the result is vat = 1246.90

but in calculator or in excel is 12.469

any idea? thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,547

Hi,

Check whether the fixed point arithmetic is checked or not. This makes lot of difference. To check this Goto Attributes of your report, a pop up window appears. Here you have that checkbox Fixed Point Arithmetic. Check it, Save and Close.

Regards,

Swapna.

12 REPLIES 12
Read only

Former Member
0 Likes
1,547

Hi..

It is with the decimal declaration I suppose.. Could you try declaring it with p decimal 1 instead of 2 and check if ur getting the same result.

Regards,

Vishwa.

Read only

Former Member
0 Likes
1,548

Hi,

Check whether the fixed point arithmetic is checked or not. This makes lot of difference. To check this Goto Attributes of your report, a pop up window appears. Here you have that checkbox Fixed Point Arithmetic. Check it, Save and Close.

Regards,

Swapna.

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,547

hi,

two things:

1. pls. check if Fixed point arithmetic is ticked in Program Attributes

2. Always multiply first and divide later for higher accuracy.

hope this helps

ec

Read only

Former Member
0 Likes
1,547

hii

I think the problem is with the declaration... Just try the same calculation by declaring it with p decimal 1 instead of 2.

Regards,

Vishwa.

Read only

Former Member
0 Likes
1,547

Please check if the 'Fixed point arithmetic' check box is ticked in the attributes of your program.

Read only

Former Member
0 Likes
1,547

Check below code....

data: v_kbetr type p decimals 2,

v_netwr type p decimals 2,

v_temp type p decimals 3.

v_netwr = '249.38'.

v_kbetr = '50.00'.

v_temp = v_kbetr / 1000.

v_temp = v_temp * v_netwr.

write:/ v_temp.

Output is 12.469

Read only

Former Member
0 Likes
1,547

u divide the result by 1000.

Regards

Anbu

b

Read only

Former Member
0 Likes
1,547

Hi,

The below code is working fine

data: vat type p decimals 2,

netwr type p decimals 2,

kbetr type p decimals 2.

netwr = '249.38'.

kbetr = '50.00'.

vat = ( netwr * ( kbetr / 1000 ) ).

write : vat.

Output is 12.47

Regards,

Surinder

Read only

MilindMungaji
Participant
0 Likes
1,547

IF your target field is of type P decimals 2 then it is coming 12.47, right result...............

Read only

Former Member
0 Likes
1,547

Hi,

I have executed your code and made some chnages it is working fine copy paste the code and check

DATA: NETWR TYPE P VALUE '249.38',

KBETR TYPE P VALUE '50.00',

VAT TYPE P DECIMALS 3.

VAT = ( NETWR * ( KBETR / 1000 ) ).

WRITE: VAT.

VAT = 12.450

Hope this helps you.

Cheers!!

Read only

Former Member
0 Likes
1,547

Hi,

Plz write the code this way it works try :

data: vat type p decimals 3,
      netwr type p decimals 2,
      kbetr type p decimals 2,
      tmp_var type p decimals 2.


netwr = '249.38'.
kbetr = '50.00'.


tmp_var = kbetr / 1000.

vat = ( netwr * tmp_var ).


vat = netwr * tmp_var.

write: vat.

o/p : 12.469.

thanx.

Read only

Former Member
0 Likes
1,547

Hi

thanks to all it solve my problem, the bottom problem is FIX POINT ARITHMETIC though i have also the right formula and all of you. I love this forum...

hope you got all your points