crafuse
asked on
Format a string as a number with commas
I use the following string format in VBA, no problems:
Format(strApplno, "0\,000\,000")
where string strApplno = "1234567"
result: "1,234,567"
This IS NOT working in VB.NET, and it's driving me crazy - I've tried all sorts of things. Any help would be great appreciated...
crafuse
Format(strApplno, "0\,000\,000")
where string strApplno = "1234567"
result: "1,234,567"
This IS NOT working in VB.NET, and it's driving me crazy - I've tried all sorts of things. Any help would be great appreciated...
crafuse
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would use:
Dim numb as String = "1234567"
Dim formatted as String = [Int32].Parse(numb).ToStri ng("#,##0" )
Dim numb as String = "1234567"
Dim formatted as String = [Int32].Parse(numb).ToStri
If you have VB.Net 2005 (or above) then use Integer.TryParse() like this:
Dim strApplno As String = "1234567"
Dim strFormattedApplno As String = ""
Dim Applno As Integer
If Integer.TryParse(strApplno , Applno) Then
strFormattedApplno = Applno.ToString("#,##0")
Else
strFormattedApplno = "{Invalid Integer}"
End If
MessageBox.Show(strFormatt edApplno)
Otherwise, we should enclose all the previous submissions in a Try/Catch block to catch the exception.
Dim strApplno As String = "1234567"
Dim strFormattedApplno As String = ""
Dim Applno As Integer
If Integer.TryParse(strApplno
strFormattedApplno = Applno.ToString("#,##0")
Else
strFormattedApplno = "{Invalid Integer}"
End If
MessageBox.Show(strFormatt
Otherwise, we should enclose all the previous submissions in a Try/Catch block to catch the exception.
ASKER
Thanks!
Dim strApplno As String = "1234567"
Debug.Print(CInt(strApplno
(assuming that "strApplno" has a VALID Integer in it)