When should I use double instead of decimal?

后端 未结 12 1586
Happy的楠姐
Happy的楠姐 2020-11-22 10:51

I can name three advantages to using double (or float) instead of decimal:

  1. Uses less memory.
  2. Faster because flo
12条回答
  •  失恋的感觉
    2020-11-22 11:42

    Decimal has wider bytes, double is natively supported by CPU. Decimal is base-10, so a decimal-to-double conversion is happening while a decimal is computed.

    For accounting - decimal
    For finance - double
    For heavy computation - double
    

    Keep in mind .NET CLR only supports Math.Pow(double,double). Decimal is not supported.

    .NET Framework 4

    [SecuritySafeCritical]
    public static extern double Pow(double x, double y);
    

提交回复
热议问题