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: 

In reference to Thread Rounding a float value.

Former Member
0 Kudos

Hi Friends,

I am trying to round a float value.

Suppose the value is 1.6666666666666666E-01

I need the output as 1.67

I hve been using ROUND function module but it gives me 1.6700000000E-01

when I use Packed decimal it takes as 0.17

Any suggestions..

Thanks

Chaithanya

Here is my above thread. I have a new issue with the abve Thread

As Rich suggested I multiplied by 10 and I got the value as 1.67.

But if the value is 1.0000000000000000E+00

when I multiply by 10. I get the value as 10.000 which is wrong

Any suggestions that would solve the issue for all the cases.

Thanks,

Chaithanya K

7 REPLIES 7

Former Member
0 Kudos

Hi Chaitanya,

You can check with the abap statements CEIL or FLOOR OR try with the function module ROUND_AMOUNT

or

CALL FUNCTION 'HR_IN_ROUND_AMT'

EXPORTING

amount = p_amt

rndoff = '100'.

RNDLMT = 'N'

IMPORTING

RETAMT =

DLTAMT =

hope this helps u .....

REWARD IF USEFUL

thanks and regards

suma sailaja

Former Member
0 Kudos

Hi Chaitanya,

try using the code like this..

DATA: num1 TYPE f, num2 TYPE p DECIMALS 2.

num1 = 73050 * '0.0727'. " result: 5.3107349999999997E+03

num2 = num1. WRITE num2. " result: 5310.73

Reward points if useful

Regards,

Goutham.

0 Kudos

Hi..

Thanks for your replies.

I have the float value already.

num1 is type float and num2 is type p decimals 3.

Say Eg num1 = 1.6666666666. when num2 = num1.

the value of num2 = 0.167. But the correct value is 1.67.

Hope this clears you

Thanks,

chaithanya.

0 Kudos

Hello Chaitanya,

it gives you 1.667 as your statement has 'decimals 3'. num2 is not 0.167...it comes to 1.667. try executing this code of yours in se38 once.

DATA: num1 TYPE f, num2 TYPE p DECIMALS 3.

num1 = '1.666666'.

num2 = num1.

WRITE num2.

Reward ponts if useful

Regards,

Goutham.

Former Member
0 Kudos

Hi Chaitanya,

You can use the Function Module

'MURC_ROUND_FLOAT_TO_PACKED'.

Reward points if helpfull.

Regards,

Kashyap Ivaturi

0 Kudos

Hi Kashyap,

Thanks for your reply. When I try to execute the function module through SE37. It says Error generating the test frame before I try to give the data.

After some analysis and time taken

The value I had was 1.6666666666666666E-01 which was raised to power -1 and Srinivas has already mentioned in my previous thread so the when 0.166666666666 is converted to packed decimal the value would be 0.167. which is correct

Thanks to all for your replies.

regards,

chaithanya K

Former Member
0 Kudos

Solved