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

后端 未结 8 2078
猫巷女王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条回答
  •  萌比男神i
    2021-01-27 12:50

    If you are using any of the numeric data types (e.g. double, single, integer, decimal), you cannot represent 10.0 and 10 as two different and distinct values. There is no way to do that. If you need to keep the mantissa of the number, even when it is zero, you will have to store the value as some other data type such as a string.

    To validate a string that has been entered, you could do something like this:

    Public Function MantissaIsZero(ByVal value As String) As Boolean
        Dim result As Boolean = False
        Dim parts() As String = value.Split("."c)
        If parts.Length = 2 Then
            Dim mantissa As Integer = 0
            If Integer.TryParse(parts(1), mantissa) Then
                result = (mantissa = 0)
            End If
        End If
        Return result
    End Function
    

提交回复
热议问题