C# issue with double number

This question already has an answer here:

  • Difference between decimal, float and double in .NET? 17 answers

  • Welcome to floating point precision. Use the decimal type if you want more precision.

    decimal my_value = 0.49m;
    

    If you want to learn more on why this is I recommend you read this article - What Every Computer Scientist Should Know About Floating-Point Arithmetic


    Use decimal instead, double is floating binary point type.

    decimal my_value = 0.49m;
    

    Useful links;

  • Floating-Point Representation and Precision
  • What Every Computer Scientist Should Know About Floating-Point Arithmetic

  • Do not use the double type when you need to use exact values. That is the domain of the decimal type

    decimal my_value = 0.49m;
    
    链接地址: http://www.djcxy.com/p/21344.html

    上一篇: >小数不完全

    下一篇: C#问题与双号码