代码之家  ›  专栏  ›  技术社区  ›  Maas

无计算的双舍入误差

  •  1
  • Maas  · 技术社区  · 7 年前

    我在C#(.Net 4.6.1)中观察到一个(对我来说)奇怪的问题,即浮点变量。

    我有一个自己的简单点类:

    public class Point
    {
        public readonly double X;
        public readonly double Y;
    
    
        public Point(double x, double y)
        {
            this.X = x;
            this.Y = y;
        }
    
        //...
    
    }
    

    calling the Contains method

    inside the called Contains method

    这里有什么问题? 为什么在被调用的方法中还有另一个值?

    最后,该值没有变化。因此,在调用方方法中,该值稍后仍然可以。

    Maas公司

    1 回复  |  直到 7 年前
        1
  •  0
  •   Maas    7 年前

    public override string ToString()
    {
        return $"{this.X};{this.Y}";
    }
    

    该值在调用方方法中也存在舍入错误。