Java Reference
In-Depth Information
Constructor
Description
COBOL Equivalent
BigInteger (String val)
Converts the decimal String
MOVE WITH CONVERSION
representation of a number into a
STRING1 TO INTEGER-NUM1
BigInteger
BigInteger (byte[ ] val)
Converts a byte array that contains
MOVE GROUP-ITEM1 TO
the 2's complement binary
INTEGER-NUM-GROUP-ITEM1
representation of a BigInteger into
a BigInteger
* Some COBOL compilers do support floating-point numerics.
Let's compare some COBOL statements that use packed numbers to their Java
equivalents that use BigDecimal s.
01 DECIMAL-ITEMS USAGE IS COMP-3.
03 DOLLAR-AMOUNT PIC S9(7)V(2) VALUE "1234567.12".
03 CURRENCY-RATE PIC S9(3)V9(5) VALUE "123.12345".
03 EXCHANGE-AMOUNT PIC S9(10)V9(4).
MULTIPLY DOLLAR-AMOUNT BY CURRENCY-RATE GIVING
EXCHANGE-AMOUNT.
Note that there is the real possibility that the result of this multiplication may
not fit in EXCHANGE-AMOUNT, and the value that is placed in this variable will
be an approximation of the actual result. By default, COBOL will truncate the in-
termediate result to fit the target variable.
The most straightforward way to handle this situation is to define a larger tar-
get variable.
01 DECIMAL-ITEMS USAGE IS COMP-3.
03 DOLLAR-AMOUNT PIC S9(7)V(2) VALUE "1234567.12".
03 CURRENCY-RATE PIC S9(3)V9(5) VALUE "123.12345".
03 EXCHANGE-AMOUNT PIC S9(10)V9(7).
MULTIPLY DOLLAR-AMOUNT BY CURRENCY-RATE GIVING
EXCHANGE-AMOUNT.
In this example, EXCHANGE-AMOUNT will always be able to contain the re-
sult. The advantage of fixed-decimal arithmetic is that the developer can always
control the precision of the result by managing the size of the result variable(s).
 
Search WWH ::




Custom Search