本文整理匯總了VB.NET中System.Decimal.ToString方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Decimal.ToString方法的具體用法?VB.NET Decimal.ToString怎麽用?VB.NET Decimal.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Decimal
的用法示例。
在下文中一共展示了Decimal.ToString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1:
Dim value As Decimal = -16325.62d
' Display value using the invariant culture.
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture))
' Display value using the en-GB culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")))
' Display value using the de-DE culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")))
' This example displays the following output to the console:
' -16325.62
' -16325.62
' -16325,62
示例2:
Dim value As Decimal = 16325.62d
Dim specifier As String
Dim culture As CultureInfo
' Use standard numeric format specifiers.
specifier = "G"
culture = CultureInfo.CreateSpecificCulture("eu-ES")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: 16325,62
Console.WriteLine(value.ToString(specifier, CultureInfo.InvariantCulture))
' Displays: 16325.62
specifier = "C"
culture = CultureInfo.CreateSpecificCulture("en-US")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: $16,325.62
culture = CultureInfo.CreateSpecificCulture("en-GB")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: £16,325.62
specifier = "E04"
culture = CultureInfo.CreateSpecificCulture("sv-SE")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: 1,6326E+004
culture = CultureInfo.CreateSpecificCulture("en-NZ")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: 1.6326E+004
specifier = "F"
culture = CultureInfo.CreateSpecificCulture("fr-FR")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: 16325,62
culture = CultureInfo.CreateSpecificCulture("en-CA")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: 16325.62
specifier = "N"
culture = CultureInfo.CreateSpecificCulture("es-ES")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: 16.325,62
culture = CultureInfo.CreateSpecificCulture("fr-CA")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: 16 325,62
specifier = "P"
culture = CultureInfo.InvariantCulture
Console.WriteLine((value/10000).ToString(specifier, culture))
' Displays: 163.26 %
culture = CultureInfo.CreateSpecificCulture("ar-EG")
Console.WriteLine((value/10000).ToString(specifier, culture))
' Displays: 163.256 %
示例3:
Dim value As Decimal = 16325.62d
Dim specifier As String
' Use standard numeric format specifiers.
specifier = "G"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: G: 16325.62
specifier = "C"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: C: $16,325.62
specifier = "E04"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: E04: 1.6326E+004
specifier = "F"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: F: 16325.62
specifier = "N"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: N: 16,325.62
specifier = "P"
Console.WriteLine("{0}: {1}", specifier, (value/10000).ToString(specifier))
' Displays: P: 163.26 %
' Use custom numeric format specifiers.
specifier = "0,0.000"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: 0,0.000: 16,325.620
specifier = "#,#.00#;(#,#.00#)"
Console.WriteLine("{0}: {1}", specifier, (value*-1).ToString(specifier))
' Displays: #,#.00#;(#,#.00#): (16,325.62)
示例4: Displays
Dim value As Decimal = -16325.62d
' Display value using default ToString method.
Console.WriteLine(value.ToString()) ' Displays -16325.62
' Display value using some standard format specifiers.
Console.WriteLine(value.ToString("G")) ' Displays -16325.62
Console.WriteLine(value.ToString("C")) ' Displays ($16,325.62)
Console.WriteLine(value.ToString("F")) ' Displays -16325.62
示例5: PiggyBank
Class PiggyBank
Public Sub AddPenny()
MyFortune = [Decimal].Add(MyFortune, 0.01D)
End Sub
Public Overrides Function ToString() As String
Return MyFortune.ToString("C") + " in piggy bank"
End Function
Protected MyFortune As Decimal
End Class