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

后端 未结 3 1627
走了就别回头了
走了就别回头了 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:15

    Well, mathematically 0.99999... == 1. Have a look at http://en.wikipedia.org/wiki/0.999... I know that programtically it poses some problems, but it's not totally a floating-point issue.

提交回复
热议问题