stevenengland / FinCalcR

A calculator specialized for financial math
MIT License
1 stars 0 forks source link

Switch from double to decimal calculation #2

Open stevenengland opened 3 years ago

stevenengland commented 3 years ago

The internal calculations use double values rather than decimal ones. At the moment there is no need for decimals. But as the calculator evolves maybe decimals will be important.

stevenengland commented 3 years ago

Might be most feasable if I could switch to C#9 where generic nullable types are allowed. That way I could change IMemoryFieldValue to be T? so that I can also set calculated results to null that threw an error like here:

// If I ever switch to decimal I should try to introduce nullable types which is fine in C#9
            this.MemoryFields.Get<double>(MemoryFieldNames.RepaymentRateNumber).Value =
                isFiniteNumber ? calculationResult : double.NaN;

Should become

// If I ever switch to decimal I should try to introduce nullable types which is fine in C#9
            this.MemoryFields.Get<decimal>(MemoryFieldNames.RepaymentRateNumber).Value =
                isFiniteNumber ? calculationResult : null;

Which can be handled nicely by the number to string formatter for the representation in the ui.