C# float bug? 0.1 - 0.1 = 1.490116E-08

后端 未结 5 578
自闭症患者
自闭症患者 2020-12-03 16:23

What\'s going on?! Subtraction works fine until I get to 0.1 - 0.1. I\'m in visual c# 2008 using the nonoba.com API.

Console.WriteLine(\"hit! \" + Users[targ         


        
5条回答
  •  感情败类
    2020-12-03 17:05

    Floating point math is always approximate, in any language, because that's how CPUs work. If you care about the absolute precision of your answers - for example, because you're dealing with money - then you shouldn't use floating point.

提交回复
热议问题