How to get the first digit after the decimal point of a float number in VB.NET

2 Answers

0 votes
Imports System
 
Public Class Test
    Public Shared Sub Main()
        Dim f As Single = 7312.891
        Dim s As String = f.ToString()
        
        Console.Write(s.Substring(s.IndexOf(".") + 1, 1))
    End Sub
End Class
 
 
 
' run:
'
' 8
'

 



answered Aug 30, 2019 by avibootz
edited Aug 30, 2019 by avibootz
0 votes
Imports System

Public Class Test
    Public Shared Sub Main()
        Dim f As Single = 23.8746

        Console.Write(Int((Math.Floor(Math.Abs(f) * 10)) Mod 10))
    End Sub
End Class



' run:
'
' 8
'

 



answered Aug 31, 2019 by avibootz
...