2007 May 07 6:13 AM
what is the exact difference between packed and float decimals.expalin with example if possible.
2007 May 07 6:14 AM
Hi
Packed numbers - type P
Type P data allows digits after the decimal point. The number of decimal places is generic, and is determined in the program. The value range of type P data depends on its size and the number of digits after the decimal point. The valid size can be any value from 1 to 16 bytes. Two decimal digits are packed into one byte, while the last byte contains one digit and the sign. Up to 14 digits are allowed after the decimal point. The initial value is zero. When working with type P data, it is a good idea to set the program attribute Fixed point arithmetic.Otherwise, type P numbers are treated as integers.
You can use type P data for such values as distances, weights, amounts of money, and so on.
Floating point numbers - type F
The value range of type F numbers is 1x10*-307 to 1x10*308 for positive and negative numbers, including 0 (zero). The accuracy range is approximately 15 decimals, depending on the floating point arithmetic of the hardware platform. Since type F data is internally converted to a binary system, rounding errors can occur. Although the ABAP processor tries to minimize these effects, you should not use type F data if high accuracy is required. Instead, use type P data.
You use type F fields when you need to cope with very large value ranges and rounding errors are not critical.
Using I and F fields for calculations is quicker than using P fields. Arithmetic operations using I and F fields are very similar to the actual machine code operations, while P fields require more support from the software. Nevertheless, you have to use type P data to meet accuracy or value range requirements.
Reward points if useful
Regards
Anji
2007 Oct 23 1:31 PM
Hi reddy ,
Can u give me an example , about type p only and explanation about it
2007 May 07 6:16 AM
2007 May 07 6:17 AM
Hi,
Packed numbers - type P
Type P data allows digits after the decimal point. The number of decimal places is generic, and is determined in the program. The value range of type P data depends on its size and the number of digits after the decimal point. The valid size can be any value from 1 to 16 bytes. Two decimal digits are packed into one byte, while the last byte contains one digit and the sign. Up to 14 digits are allowed after the decimal point. The initial value is zero. When working with type P data, it is a good idea to set the program attribute Fixed point arithmetic.Otherwise, type P numbers are treated as integers.
You can use type P data for such values as distances, weights, amounts of money, and so on.
Floating point numbers - type F
The value range of type F numbers is 1x10*-307 to 1x10*308 for positive and negative numbers, including 0 (zero). The accuracy range is approximately 15 decimals, depending on the floating point arithmetic of the hardware platform. Since type F data is internally converted to a binary system, rounding errors can occur. Although the ABAP processor tries to minimize these effects, you should not use type F data if high accuracy is required. Instead, use type P data.
You use type F fields when you need to cope with very large value ranges and rounding errors are not critical.
Using I and F fields for calculations is quicker than using P fields. Arithmetic operations using I and F fields are very similar to the actual machine code operations, while P fields require more support from the software. Nevertheless, you have to use type P data to meet accuracy or value range requirements.
Examples are:
1.DATA float TYPE f VALUE '123456789.0'.
WRITE float EXPONENT 3.
123456,789E+03
2.DATA pack TYPE p VALUE '123.456'
DECIMALS 3.
WRITE pack DECIMALS 2.
WRITE: / pack ROUND -2,
/ pack ROUND -1,
/ pack ROUND 1,
/ pack ROUND 2.
123,46
12.345,600
1.234,560
12,346
1,235
2007 May 07 6:33 AM
Hi Manjula,
You can refer to this question.
Can u print decimals in type N? What is difference between float and packed data type?
Ans No, we cannot print decimals in type N because decimal places are not permitted with N data type. Float Data Type: It cannot be declared in Parameters. Packed Number: It can be declared in Parameters. For e.g. PARAMETERS : A(4) TYPE P DECIMALS 2, B(4) TYPE P DECIMALS 2. DATA : C(4) TYPE P DECIMALS 2. C = A + B. WRITE : / THE SUM IS , C.
Regards,
Jayant