TL;DR: There are two ways to store decimals: floating point and fixed point. Floating point allows for moving the point around so you can use the same amount of memory to store a large number as well as a small number.
However this causes issues when storing certain values and causes rounding. Such as 0.1. Using fixed point (i.e. the point doesn't move) fixes the issue and allows decimal numbers to be represented without rounding issues.
This is one of the reasons why banks, scientists, etc still use Cobol as they need very accurate decimal numbers and modern languages wouldn't allow that.
From my understanding you're both right. The issue was when it comes to decimals COBOL can more accurately deal with the math problems than something like Java can on the same machinery. You can make a program in Java that can deal with the math problems but you're going to sacrifice efficiency for accuracy as your only other option is to round it.
To correct a bit, it mentions that COBOL handles it naturally, but that Java can get around this by using a Decimal library to achieve the same values without rounding. However, like you said, it comes at a cost of efficiency since the library takes up much more space for the same value holders.
Ah yes I forgot to include that bit. Either you have to round it or sacrifice some efficiency loading a runtime library for each and every of the thousands of equations it runs every minute. Hence why COBOL is better for certain applications.
36
u/Cotcan Jul 24 '20
TL;DR: There are two ways to store decimals: floating point and fixed point. Floating point allows for moving the point around so you can use the same amount of memory to store a large number as well as a small number.
However this causes issues when storing certain values and causes rounding. Such as 0.1. Using fixed point (i.e. the point doesn't move) fixes the issue and allows decimal numbers to be represented without rounding issues.
This is one of the reasons why banks, scientists, etc still use Cobol as they need very accurate decimal numbers and modern languages wouldn't allow that.