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

Float vs Packed Number

Former Member
6,374

Dear Experts,

Really really appreciate if you could kindly help and share a glimpse on light on the following question:

May I know why for the same number with decimal, e.g. '35.54', can yield different result if I'm using different type of variable?

Below are the my source code and the result.

DATA:     float type f,

              pn type p decimals 2.

           float = '35.54'.

           pn = '35.54'.

     

           write: / float.

           write: / pn.

Millions Thanks!

5 REPLIES 5
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
2,921
Yes.
Check F1 help for data types P and F and you can see the difference.
  • You use type F fields when you need to cope with very large value ranges and
    rounding errors are not critical

Message was edited by: Rob Burbank

Read only

Former Member
0 Likes
2,921

Hii ,

Since Float will display as  3,55399999999999E+01 as   3.5 * 10 ( power of 1)  which is equivalent answer to the value. Since Float doesn't allow decimals.

If you used Packed Numbers, decimal point is fixed to places it would give you approx value. Here its 2 places so it would give the required .

try to use new keywords such as 'DECFLOAT16' and 'DECFLOAT32' which is a mixture of both decimal float number.

for further reference please try to read CD205 Advance ABAP topics for futher information.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,921

In computer arithmetic, only integer calculations are accurate, every other operation will round the results. Even a move is rounding the result.

- type p decimals 2. is actually an integer, with a virtual decimal position, no rounding.

- float is not an integer so the default value was converted and rounded.

Regards,

Raymond

Read only

Former Member
2,921

Hi,

  1. FLOAT has default decimal places of 16 & PACKED data type has 0. 
  2. FLOAT decimal places are fixed whereas can be decided by the ABAPer for PACKED. 

Read only

Former Member
0 Likes
2,921

Hi,

The difference is as:

<< Moderator message - Cut and paste response from http://scn.sap.com/thread/542914 removed and points unassigned. Plagiarism is not allowed in SCN >>

For further information please refer the folowing threads

http://scn.sap.com/thread/1497542

Point begging also removed.

Regards

Resh

Message was edited by: Rob Burbank