decimal vs double

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John A Grandy

    decimal vs double

    Apparently, financial calculations should be performed with decimal not
    double, however .NET does not make it easy to work with decimal.

    Literal numeric non-integral values are by default treated as doubles.

    The constants in System.Math (Pi,E) are doubles.

    What are the relative benefits of using decimal to store financial data ?



  • Jeroen Mostert

    #2
    Re: decimal vs double

    John A Grandy wrote:
    Apparently, financial calculations should be performed with decimal not
    double, however .NET does not make it easy to work with decimal.
    >
    Literal numeric non-integral values are by default treated as doubles.
    >
    Use the suffix "m" to declare decimal literals.
    The constants in System.Math (Pi,E) are doubles.
    >
    They're more commonly used as doubles than as decimals. If you need them
    (which should be relatively rare for a financial application) it's easy
    enough to declare a class yourself, though:

    public static class MathD {
    public const decimal PI = 3.1415926535897 932384626433832 79m;
    public const decimal E = 2.7182818284590 452353602874713 5m;
    ...
    }
    What are the relative benefits of using decimal to store financial data ?
    >
    This page explains it better than I could:


    In short, floating-point calculations are subject to errors that are quickly
    apparent in financial applications, which require exact representations of
    exact values (as opposed to approximating everything that's not exactly
    representable in binary, as floating point does). Decimals can offer this.

    --
    J.

    Comment

    • =?windows-1252?Q?Arne_Vajh=F8j?=

      #3
      Re: decimal vs double

      Jeroen Mostert wrote:
      John A Grandy wrote:
      >The constants in System.Math (Pi,E) are doubles.
      They're more commonly used as doubles than as decimals. If you need them
      (which should be relatively rare for a financial application
      I think that is an understatement !
      >What are the relative benefits of using decimal to store financial data ?
      This page explains it better than I could:
      http://www2.hursley.ibm.com/decimal/decifaq1.html
      Actually a very interesting page !

      Arne

      Comment

      Working...