decimal rounding is off for (276/304)*304

后端 未结 3 1586
走了就别回头了
走了就别回头了 2021-01-18 06:32

If you put the following code in your compiler the result is a bit bizar:

decimal x = (276/304)*304;
double y = (276/304)*304;

Console.WriteLine("decima         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 07:16

    Well, floating point precision isn't 100%.
    See for example: http://effbot.org/pyfaq/why-are-floating-point-calculations-so-inaccurate.htm

提交回复
热议问题