11-27-2008 11:18 AM
Hi,
I have following problem:
DATA:
l_value_p TYPE p LENGTH 11 DECIMALS 8 value '33.33333333',
l_value_f TYPE f.
l_value_f = l_value_p.
The result is that l_value_f has value 3.3333333330000002E01. How come there is 2 at the end? I need value 3.3333333330000000E01. Seems to be some rounding issue. Does anybody know how to get rid of this rounding?
Thanks in advance,
Tomas
11-27-2008 11:29 AM
Hi,
The number of bytes in both cases do not match correctly.
Hence i believe a garbage value is inserted.
try the following code.
DATA:
l_value_p TYPE p LENGTH 11 DECIMALS 7 value '33.33333333', " value
l_value_f TYPE f.
l_value_f = l_value_p.
Write: l_value_f.
hope this helps,
Raj
11-27-2008 11:29 AM
Hi,
The number of bytes in both cases do not match correctly.
Hence i believe a garbage value is inserted.
try the following code.
DATA:
l_value_p TYPE p LENGTH 11 DECIMALS 7 value '33.33333333', " value
l_value_f TYPE f.
l_value_f = l_value_p.
Write: l_value_f.
hope this helps,
Raj
11-27-2008 11:50 AM
Hi Raj,
thanks for your solution, in this way, the value is really converted precisely, but I simply cannot cut the last decimal number, I have to consider all 8 decimal numbers.
Any other idea?
11-27-2008 11:58 AM
Hi Tomas,
Try this piece of code.
DATA:
l_value_p TYPE p LENGTH 11 DECIMALS 7 value '33.33333333', " value
l_char(11),
l_value_f TYPE f.
l_char = l_value_p.
l_value_f = l_char.
Write: l_value_f.
-Regards,
Raj
Edited by: Rajat Chaturvedi on Nov 27, 2008 5:30 PM
11-27-2008 12:43 PM
Hi Raj, this solution with l_char does not work for number with 8 decimal places either.
11-27-2008 12:08 PM
Hi,
Execute this code.
DATA:
l_value_p TYPE p LENGTH 11 DECIMALS 8 value '33.33333333',
l_value_f TYPE float.
(I just changed type f to float)
l_value_f = l_value_p.
write l_value_f.
OUTPUT: 3.333333333000000E+01
Thanks
Nitesh
11-27-2008 12:52 PM
Hi Nitesh,
your solution surprised me - just changing "F" to "FLOAT".
Unfortunately, it does not work either. The value is printed correctly by WRITE but internally inside variable l_value_f it still holds value "3.3333333330000002E+01" and this is my problem.
I need the internal value of l_value_f to be 3.3333333330000000E+01.
To my understanding, this is problem cannot be solved.
This is because of type float - the conversion of any kind of numbers into float number is very dangerous and the result is unpredictable. I think we have to reconcider the usage of float in our application art the first place.
Thanks anyway, Tomas
11-27-2008 12:45 PM
11-27-2008 12:48 PM
Tomas,
It works!!!
I can see the result on my system.
Can you plz check again and let me know.
Regards,
Raj
11-27-2008 1:00 PM
Hi Raj, you are right, it works but only if the DECIMAL is 7, not if the DECIMAL is 8. And I cannot use DECIMAL 7 because I must not cut the last number.
That means, I need value
33,33333333
and not value
33,3333333
Thanks anyway, Tomas
04-03-2009 1:49 PM
As mentioned above, there is no solution for this because float is never so precise. Not all number can be described by float, for example this number.