I have a requirement to take legacy code in an XBase-style language (FoxPro, in this case) and convert it to C#.NET. I want to get identical output from my rewrite, but rounding discrepancies are driving me nuts. I tried Decimal.Round(MidpointRounding) stuff alone, but found that I also needed to write my own "round up" function for midpoint = 5 situations.
That would be fine, if it worked, but what I'm seeing is that the my "round up" method is needed to agree with FoxPro output in some cases, but actually creates discrepancies in others. The database query is doing some multiplication and division, and I'm wondering whether math discrepancies between the two systems are accumulating.
Here is an example of what seems to me to be an inconsistency. The initial value of each pair comes from the output of my LINQ query. Given these, I want to generate a rounded result that is identical to the FoxPro result shown:
.NET LINQ Query result: 7.0477049103806673503597572093.
FoxPro rounding: 7.0
.NET LINQ: 7.2499596595318807183725770943.
FoxPro rounding: 7.3
Any suggestions as to how I can exactly duplicate the value from the legacy system without out resorting to a completely kludgey hack?