VB.Net Tutorial/Data Type/Numeric format

Материал из VB Эксперт
Перейти к: навигация, поиск

Numeric format: {0:N}, {1:E} and G5

<source lang="vbnet">Public Class Tester

   Public Shared Sub Main
       Dim intValue As Integer = 1234567
       Dim floatValue As Double = Math.PI
       Dim result As New System.Text.StringBuilder
       result.AppendLine(String.Format("{0}  ...  {1}", _
          intValue, floatValue))
       result.AppendLine(String.Format("{0:N}  ...  {1:E}", _
          intValue, floatValue))
       result.AppendLine(intValue.ToString("N5") & "  ...  " & _
          floatValue.ToString("G5"))
       Console.WriteLine(result.ToString())

   End Sub

End Class</source>

1234567  ...  3.14159265358979
1,234,567.00  ...  3.141593E+000
1,234,567.00000  ...  3.1416