Here's a few examples of formatting numbers to give you a flavor of what can be done.
Big numbers are usually displayed using an "exponential" format. Suppose you wanted to display the national debt of the U.S. (as of September 11, 2009) in dollars. You could write:
$11,799,461,425,415
or you could write:
1.18E+13
The second example might be more appropriate these days since it's such a huge number. But you can use a format specifier to display either one:
Dim NatDebt As Int64 = 11799461425415
MsgBox(String.Format("{0:C}", NatDebt))
MsgBox(String.Format("{0:E2}", NatDebt))
(It's such a big number that a 32 bit integer isn't big enough.)
You can also include other text in the format specifier. For example, one way to display ...
On 9/11, 2009,
the U.S. National Debt was
$11,799,461,425,415.00.
... is ...
MsgBox(String.Format("On 9/11, 2009," & _
vbCrLf & "the U.S. National Debt was" & _
vbCrLf & "{0:C}.", NatDebt))
The "index" in the format specifier has always been equal to 0 in the examples so far. This way of identfying substitution variables goes back a long way but might be unfamiliar to some people learning VB.NET. Here's a more complex example that shows how to use both the index and StringBuilder to build a report from multiple elements. If you were reading values from a database, you could build a complex output the same way.
Dim DailyNatDebt As Int64
Dim i As Int16
Dim DebtDisplay As New System.Text.StringBuilder
DebtDisplay.Append(vbCrLf)
DebtDisplay.Append(String.Format("From {0:D} " & vbCrLf & _
" to {1:D} " & vbCrLf & _
" the U. S. national debt was: " & vbCrLf, _
Today.AddDays(1), Today.AddDays(9)))
DailyNatDebt = 11799461425415
For i = 1 To 9
DailyNatDebt += 3910000000
DebtDisplay.Append(String.Format("{0:C} on {1:D}" _
& vbCrLf, DailyNatDebt, Today.AddDays(i)))
Next
MsgBox(DebtDisplay.ToString)
Notes: DailyNatDebt is plugged into the 0 index and Today is plugged into the 1 index. As the article StringBuilder ... A New Object in .NET shows, avoiding the use of string concatenation using the & operator would have been more efficient, but the constant vbCrLf can't be embedded in the format specifier! Also, the illustration below was created for the original article but the numbers have been updated in the code example above. Quite a difference!
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

