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

Rounding problem

Former Member
0 Likes
873

the result is 98,067 and I want to show 98,07 but if the result 98,064 I want to show 98,06 simple rules of rounding !!, but How can I do that within the program? . Is there a easy way to do that?.

I have fixed point arithmetic uncheked for this code:

DATA: lv_kwert2 TYPE p DECIMALS 3,

gv_kwert2 LIKE konv-kwert,

tvbdpr-fkimg LIKE VBDPR-fkimg.

lv_kwert2 = ( gv_kwert2 * 10000 ) / tvbdpr-fkimg.

Debugging the program you get the following values:

lv_kwert2 = 0.000

gv_kwert2 = 294.20

tvbdpr-fkimg = 3.000

After executing the calculation value for lv_kwert2 is 98.067. I need to round this value.

any idea would be very much appreciated.

thanks all in advance

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
781

when "fixed point arithmetic" flag is unchecked, operations on packed numbers are done as if they had no decimals at all. In your case, to round, you just have to divide by 10 (the least significant digit is cut with a commercial rounding on the previous digit), and multiply by 10.

lv_kwert2 = ( gv_kwert2 * 10000 ) / tvbdpr-fkimg / 10 * 10.

(yes I know, it's very difficult to understand, but logic with my initial explanation)

But using ROUND FM which works with "fixed point arithmetic", it's much more easier (though slower). Note that this FM has documentation. Use parameter SIGN='X' to get a commercial rounding.

3 REPLIES 3
Read only

Former Member
0 Likes
781

just use keywords like CEIL,FLOOR,TRUNC,with the variable.

like

n = func( m ).

check out this link

[Mathematical functions|http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3316358411d1829f0000e829fbfe/content.htm]

and with write statement you can use ROUND<n>

check this

[Formatting Options|http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9e3d35c111d1829f0000e829fbfe/content.htm]

Read only

Former Member
0 Likes
781

Hi,

Use the FM ROUND...and choose to have 1 decimal points.

Regards,

Himanshu

Read only

Sandra_Rossi
Active Contributor
0 Likes
782

when "fixed point arithmetic" flag is unchecked, operations on packed numbers are done as if they had no decimals at all. In your case, to round, you just have to divide by 10 (the least significant digit is cut with a commercial rounding on the previous digit), and multiply by 10.

lv_kwert2 = ( gv_kwert2 * 10000 ) / tvbdpr-fkimg / 10 * 10.

(yes I know, it's very difficult to understand, but logic with my initial explanation)

But using ROUND FM which works with "fixed point arithmetic", it's much more easier (though slower). Note that this FM has documentation. Use parameter SIGN='X' to get a commercial rounding.