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 Calculation Problem

Former Member
0 Likes
947

Hi,

I am calculating this formula

w_tax_amt = ( v_tot * konp-kbetr ) / 100

Following are the values

v_tot = 329284.57

konp-kbetr = 5.00

This yields w_tax_amt = 16464.23

I am expecting this value to be 16464.22 as using calci it comes 16464.2284

I dont want rounding to happen. How should I go about it ?

What type should I use. Currently all the tyes are of bseg-wrbtr type

Thanks

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
751

Please try this. Using FLOOR will always round down.



REPORT ZRICH_0002 .

data: v_tot type p decimals 2.
data: konp-kbetr type konp-kbetr.
data: w_tax_amt type p decimals 2.


v_tot = '329284.57' .
konp-kbetr = '5.00' .


<b>w_tax_amt = ( floor( v_tot * konp-kbetr ) ) / 100.</b>




write:/ w_tax_amt.

Welcome to SDN.

Please make sure to award points for helpful answers and mark your posts as solved when solved completely. Thanks.

Regards,

Rich Heilman

5 REPLIES 5
Read only

Former Member
0 Likes
751

In the editor see the setting for fixed point arithmetic.

Go to attributes in se38 and see if the check box for fixed point arithmetic is checked or not.

Regards,

Vamsi.

Read only

Former Member
0 Likes
751

Declare the variable w_tax_amt with 3 or 4 decimals and then use the truncate function.

Read only

Former Member
0 Likes
751

Hi,

You should use 'DECIMALS' OR 'ROUND' depending on what you need.

Effect of different DECIMALS specifications:

DATA: X TYPE P DECIMALS 3 VALUE '1.267',

Y TYPE F VALUE '125.456E2'.

WRITE: /X DECIMALS 0, "output: 1

/X DECIMALS 2, "output: 1.27

/X DECIMALS 5, "output: 1.26700

/Y DECIMALS 1, "output: 1.3E+04

/Y DECIMALS 5, "output: 1.25456E+04

/Y DECIMALS 20. "output: 1.25456000000000E+04

Effect of different ROUND specifications:

DATA: X TYPE P DECIMALS 2 VALUE '12493.97'.

WRITE: /X ROUND -2, "output: 1,249,397.00

/X ROUND 0, "output: 12,493.97

/X ROUND 2, "output: 124.94

/X ROUND 5, "output: 0.12

Hope this helps, please dont forget to reward if this was helpful,

Gabriel P,

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
752

Please try this. Using FLOOR will always round down.



REPORT ZRICH_0002 .

data: v_tot type p decimals 2.
data: konp-kbetr type konp-kbetr.
data: w_tax_amt type p decimals 2.


v_tot = '329284.57' .
konp-kbetr = '5.00' .


<b>w_tax_amt = ( floor( v_tot * konp-kbetr ) ) / 100.</b>




write:/ w_tax_amt.

Welcome to SDN.

Please make sure to award points for helpful answers and mark your posts as solved when solved completely. Thanks.

Regards,

Rich Heilman

Read only

christian_wohlfahrt
Active Contributor
0 Likes
751

Hi Nitin!

Something of topic: tax is not calculate on line level, but on header level and afterwards distributed. There can be rounding differences based on the different procedures - just in case you will compare with standard documents.

Regards,

Christian