VB.Net Tutorial/Data Type/Double Format

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

Double format: #,###.###000

Public Class Tester
    Public Shared Sub Main
        Dim dblNum As Double = 2123.456
        Console.WriteLine(dblNum.ToString("#,###.###000"))
    End Sub
End Class
2,123.456000

Double format: F2

Public Class Tester
    Public Shared Sub Main
        Dim dblNum As Double = 2123.456
        Console.WriteLine(dblNum.ToString("F2"))
    End Sub
End Class
2123.46

Double with/without format

public class Test
   public Shared Sub Main
        Dim n As Double
        n = 12
        n /= 7
        Console.WriteLine("Without formatting: " & n)
        Dim s As String
        s = String.Format("{0:n3}", n)
        Console.WriteLine("With formatting: " & s)

   End Sub
End class
Without formatting: 1.71428571428571
With formatting: 1.714