ObjectStatic: ToString |
Returns a default string representation of an object.
Public Function ToString( ByRef Value As Variant, Optional ByRef Format As String, Optional ByVal Provider As IFormatProvider ) As String
The following example uses ToString to display numeric values formatting.
Public Sub Main() Debug.Print "Print values with default formatting." Debug.Print Object.ToString(CorDateTime.Now) Debug.Print Object.ToString(1234) Debug.Print Object.ToString(1234.3254) Debug.Print t("\nPrint values with formatting.") Debug.Print Object.ToString(1234, "g2") Debug.Print Object.ToString(1234, "f2") Debug.Print Object.ToString(1234, "n2") Debug.Print Object.ToString(1234.3254, "n2") Debug.Print Object.ToString(1234, "c2") Debug.Print Object.ToString(1234.3254, "c2") Dim Provider As New NumberFormatInfo Provider.CurrencySymbol = "!" Debug.Print t("\nPrint values with custom provider.") Debug.Print Object.ToString(1234, "c2", Provider) Debug.Print Object.ToString(1234.3254, "c2", Provider) Dim FrProvider As IFormatProvider Set FrProvider = NewCultureInfo("FR-fr") Debug.Print t("\nPrint values with French provider.") Debug.Print Object.ToString(CorDateTime.Now, Provider:=FrProvider) Debug.Print Object.ToString(1234, "c2", FrProvider) Debug.Print Object.ToString(1234.3254, "c2", FrProvider) End Sub ' This example code produces the following output. ' ' Print values with default formatting. ' 4/21/2020 9:02:45 AM ' 1234 ' 1234.3254 ' ' Print values with formatting. ' 1.2e+03 ' 1234.00 ' 1,234.00 ' 1,234.33 ' $1,234.00 ' $1,234.33 ' ' Print values with custom provider. ' !1,234.00 ' !1,234.33 ' ' Print values with French provider. ' 21/04/2020 09:02:45 ' 1 234,00 € ' 1 234,33 €