Applications using Decimal versus double . .

前端 未结 7 1583
感动是毒
感动是毒 2021-01-02 19:38

I wanted to see if folks were using decimal for financial applications instead of double. I have seen lots of folks using double all over the place with unintended conseque

7条回答
  •  旧巷少年郎
    2021-01-02 20:18

    I totally agree on correctness issues of floating point vs decimal mentioned above, but many financial applications are performance critical.

    In such cases you will consider to use float/double as decimal has great impact on performance in systems where decimal types are not supported in hardware. And still it is possible to wrap floating point types in higher level classes (e.g. Tax, Commission, Balance, Dividend, Quote, Tick, etc...) that represent domain model and encapsulate all rounding logic as well as valid operators on these types and their interactions. And yes - in some projects I have implemented custom rounding functions to squeeze up to 20% more out of calculations compared to .NET or win32 methods.

    Another thing to consider is whether you pass your objects out of process, as serializing decimals which are usually 4 integers and passing them over the wire is much more CPU intensive (esp if not supported) and results in significantly more bandwidth and larger memory footprint.

提交回复
热议问题