I am re-writing a COBOL program in C# that does calculations dealing with money. From some of the first calculations however, some of the decimal rounding is off (doesn't match what the COBOL program calculates).
Decimal.Round(19.87 * 2.57, 2)
returns 51.07 (51.0659) in C#,
COMPUTE varA = 19.87 * 2.57
returns 51.06 in COBOL
Here COBOL rounds the number down, but in other cases it rounds up where C# rounds down. I'm at a loss.
This is one of the first calculations I have to do, so once the numbers get larger they are more and more different from the COBOL output. (I have a report I am testing numbers against.)
I have tried Math.Round, and Floor and Ceiling of both classes to get the output I should see to no avail.
UPDATE: I found what my problem was. Many of the fields used in the calculations in the COBOL program had 9 decimal places, but the result was stored in a 2 decimal place field. I was doing the calculations after truncating, instead of before and then truncating. Thanks everyone for your help! Every answer helped!