User Tools

Site Tools


type_conversion_and_intermediate_results.htm
Navigation:  Language Reference > 11 - Assignments > Data Type Conversion Rules >====== Type Conversion and Intermediate Results ====== Previous pageReturn to chapter overviewNext page

Internally, a BCD intermediate result may have up to 31 digits of accuracy on both sides of the decimal point, so any two DECIMALs can be added with complete accuracy. Therefore, storage from BCD intermediate results to a data type can result in loss of precision. This is handled as follows :

Decimal(x,y) = BCD First the BCD value is rounded to y decimal places. If the result overflows x digits then leading digits are removed (this corresponds to “wrapping around” a decimal counter).
Integer = BCD Any digits to the right of the decimal point are ignored. The decimal is then converted to an integer with complete accuracy and then taken modulo 232.
String(@Nx.y) = BCD The BCD value is rounded to y decimal places, the result is fitted into the pictured string. If overflow occurs, an invalid picture (####) results.
Real = BCD The most significant 15 digits are taken and the decimal point 'floated' accordingly.

For those operations and procedures that do not support DECIMAL types, the DECIMAL is converted to REAL first. In cases where more than 15 digits were available in the DECIMAL value, there is a loss of accuracy.

NoteBox.jpg

Unspecified Data Type parameters have an implicit REAL Base Type, therefore DECIMAL Base Type data passed as an Unspecified Data Type Parameters will only have 15 digits of precision. DECIMAL Base Types can be passed as *DECIMAL parameters with no loss of precision.

When EVALUATEing a expression (or processing a VIEW FILTER) the REAL Base Type is used.

Example:

!BCD to String conversion

Loc:TestVal Decimal(21,2)
Loc:TestValStr String(20)
CODE
Loc:TestVal = 11746610286892.55
 Message(Loc:TestVal) ! displays value 11746610286892.6
Loc:TestValStr = 11746610286892.55
Loc:TestVal = Loc:TestValstr
Message(Loc:TestVal) ! Displays value 11746610286892.6
Message('Formatted ' & Format(Loc:TestVal,@n-25.2)) ! Displays value 11746610286892.55
Loc:TestValStr = 11746610286892.55
Loc:TestVal = Deformat(Loc:TestValStr)
Message('Formatted ' & Format(Loc:TestVal,@n-25.2)) ! 11746610286892.55
Loc:TestValStr = 11746610286892.55
Loc:TestVal = Deformat(Loc:TestValStr,@n18.2)
Message('Formatted ' & Format(Loc:TestVal,@n-25.2)) ! 11746610286892.50
type_conversion_and_intermediate_results.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1