How to convert float to string in VB.NET

3 Answers

0 votes
Imports System
                 
Public Module Module1
    Public Sub Main()
        Dim n As Single = 6.1
        Dim s As String = n.ToString()
        Console.WriteLine("VB " + s)
                 
        n = 6.5
        s = n.ToString()
        Console.WriteLine("VB " + s)
       
        n = 6.7
        s = n.ToString()
        Console.WriteLine("VB " + s)
 
    End Sub
End Module
 
 
 
' run:
'
' VB 6.1
' VB 6.5
' VB 6.7
'

 



answered Jul 11, 2021 by avibootz
edited May 12, 2024 by avibootz
0 votes
Imports System
                 
Public Module Module1
    Public Sub Main()
        Dim n As Single = 6.1
        Dim s As String = CStr(n)
        Console.WriteLine("VB " + s)
                 
        n = 6.5
        s = CStr(n)
        Console.WriteLine("VB " + s)
       
        n = 6.7
        s = CStr(n)
        Console.WriteLine("VB " + s)
 
    End Sub
End Module
 
 
 
' run:
'
' VB 6.1
' VB 6.5
' VB 6.7
'

 



answered Jul 11, 2021 by avibootz
edited May 12, 2024 by avibootz
0 votes
Imports System
                 
Public Module Module1
    Public Sub Main()
        Dim n As Single = 872.1451f
        Dim s As String = CStr(n)
        Console.WriteLine(s)
        Console.WriteLine(n.ToString())
                 
        n = 872.1455f
        s = CStr(n)
        Console.WriteLine(s)
        Console.WriteLine(n.ToString())
       
        n = 872.1459f
        s = CStr(n)
        Console.WriteLine(s)
        Console.WriteLine(n.ToString())
 
    End Sub
End Module
 
 
 
' run:
'
' 872.1451
' 872.1451
' 872.1455
' 872.1455
' 872.1459
' 872.1459
'
'

 



answered May 12, 2024 by avibootz

Related questions

...