How to format a number with thousands separator (commas) in VB.NET

2 Answers

0 votes
Imports System
				
Public Module Module1
	Public Sub Main()
		dim x As Integer = 49876173
        
        Console.WriteLine(String.Format("{0:n}", x)) 
        Console.WriteLine(String.Format("{0:n0}", x))
	End Sub
End Module



' run:
'
' 49,876,173.00
' 49,876,173
' 

 



answered Dec 28, 2020 by avibootz
edited Aug 3, 2023 by avibootz
0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
        Dim num As Integer = 1234567
        
		Dim str As String = num.ToString("N")
        Console.WriteLine(String.Format(str))
        
		str = num.ToString("N0")
        Console.WriteLine(str)
    End Sub
End Class




' run:
'
' 1,234,567.00
' 1,234,567
'



 



answered Aug 3, 2023 by avibootz

Related questions

1 answer 257 views
1 answer 308 views
1 answer 235 views
1 answer 223 views
1 answer 210 views
1 answer 241 views
2 answers 329 views
...