How would I get the number after a decimal point in VB.NET

后端 未结 8 2092
猫巷女王i
猫巷女王i 2021-01-27 12:10

Can anyone give me an easy way to find out the numbers after the decimal point of the double?
All i need to do is to find out if the number ends in 0 like 1.0 or 10.0 or 32

8条回答
  •  渐次进展
    2021-01-27 12:37

    Do you mean something like:

    if (x == Math.Floor(x))
    

    ? Note that usually with binary floating point arithmetic, you want to have some sort of tolerance, so that 10.000001 was treated as "pretty close to 10". For example:

    if (x - Math.Floor(x) < Tolerance)
    {
        ...
    }
    

提交回复
热议问题