本文整理匯總了VB.NET中System.Int32.ToString方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Int32.ToString方法的具體用法?VB.NET Int32.ToString怎麽用?VB.NET Int32.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Int32
的用法示例。
在下文中一共展示了Int32.ToString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1:
Dim value As Integer = -16325
' 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
' -16325
' -16325
示例2: cultures
' Define cultures whose formatting conventions are to be used.
Dim cultures() As CultureInfo = {CultureInfo.CreateSpecificCulture("en-US"), _
CultureInfo.CreateSpecificCulture("fr-FR"), _
CultureInfo.CreateSpecificCulture("es-ES") }
Dim positiveNumber As Integer = 1679
Dim negativeNumber As Integer = -3045
Dim specifiers() As String = {"G", "C", "D8", "E2", "F", "N", "P", "X8"}
For Each specifier As String In specifiers
For Each culture As CultureInfo In Cultures
' Display values with "G" format specifier.
Console.WriteLine("{0} format using {1} culture: {2, 16} {3, 16}", _
specifier, culture.Name, _
positiveNumber.ToString(specifier, culture), _
negativeNumber.ToString(specifier, culture))
Next
Console.WriteLine()
Next
輸出:
G format using en-US culture: 1679 -3045 G format using fr-FR culture: 1679 -3045 G format using es-ES culture: 1679 -3045 C format using en-US culture: $1,679.00 ($3,045.00) C format using fr-FR culture: 1 679,00 € -3 045,00 € C format using es-ES culture: 1.679,00 € -3.045,00 € D8 format using en-US culture: 00001679 -00003045 D8 format using fr-FR culture: 00001679 -00003045 D8 format using es-ES culture: 00001679 -00003045 E2 format using en-US culture: 1.68E+003 -3.05E+003 E2 format using fr-FR culture: 1,68E+003 -3,05E+003 E2 format using es-ES culture: 1,68E+003 -3,05E+003 F format using en-US culture: 1679.00 -3045.00 F format using fr-FR culture: 1679,00 -3045,00 F format using es-ES culture: 1679,00 -3045,00 N format using en-US culture: 1,679.00 -3,045.00 N format using fr-FR culture: 1 679,00 -3 045,00 N format using es-ES culture: 1.679,00 -3.045,00 P format using en-US culture: 167,900.00 % -304,500.00 % P format using fr-FR culture: 167 900,00 % -304 500,00 % P format using es-ES culture: 167.900,00 % -304.500,00 % X8 format using en-US culture: 0000068F FFFFF41B X8 format using fr-FR culture: 0000068F FFFFF41B X8 format using es-ES culture: 0000068F FFFFF41B
示例3:
Dim value As Integer = -16325
Dim specifier As String
' Use standard numeric format specifier.
specifier = "G"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: G: -16325
specifier = "C"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: C: ($16,325.00)
specifier = "D8"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: D8: -00016325
specifier = "E4"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: E4: -1.6325E+004
specifier = "e3"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: e3: -1.633e+004
specifier = "F"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: F: -16325.00
specifier = "N"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: N: -16,325.00
specifier = "P"
Console.WriteLine("{0}: {1}", specifier, (value/100000).ToString(specifier))
' Displays: P: -16.33 %
specifier = "X"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: X: FFFFC03B
' Use custom numeric format specifiers.
specifier = "0,0.000"
Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
' Displays: 0,0.000: -16,325.000
specifier = "#,#.00#;(#,#.00#)"
Console.WriteLine("{0}: {1}", specifier, (value*-1).ToString(specifier))
' Displays: #,#.00#;(#,#.00#): 16,325.00
示例4: Displays
Dim value As Integer = -16325
' Display value using default ToString method.
Console.WriteLine(value.ToString()) ' Displays -16325
' Display value using some standard format specifiers.
Console.WriteLine(value.ToString("G")) ' Displays -16325
Console.WriteLine(value.ToString("C")) ' Displays ($16,325.00)
Console.WriteLine(value.ToString("D")) ' Displays -16325
Console.WriteLine(value.ToString("F")) ' Displays -16325.00
Console.WriteLine(value.ToString("N")) ' Displays -16,325.00
Console.WriteLine(value.ToString("X")) ' Displays FFFFC03B