Application Development 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: 

wrong result in simple computation

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

JozsefSzikszai
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

u divide the result by 1000.

Regards

Anbu

b

Former Member
0 Kudos

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

milusai
Participant
0 Kudos

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

Former Member
0 Kudos

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!!

Former Member
0 Kudos

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.

Former Member
0 Kudos

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