Single.TryParse converts string in a style and culture-specific format to single-precision floating-point number : Single « Data Types « VB.Net






Single.TryParse converts string in a style and culture-specific format to single-precision floating-point number

 

Module Example
   Public Sub Main()
        Dim value As String
        Dim style As System.Globalization.NumberStyles
        Dim culture As System.Globalization.CultureInfo
        Dim number As Single
        
        ' Parse currency value using en-GB culture.
        value = "1,234.56"
        style = System.Globalization.NumberStyles.Number Or _
                System.Globalization.NumberStyles.AllowCurrencySymbol
        culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB")
        If Single.TryParse(value, style, culture, number) Then
           Console.WriteLine("Converted '{0}' to {1}.", value, number)
        Else
           Console.WriteLine("Unable to convert '{0}'.", value)
        End If    

    End Sub
End Module

   
  








Related examples in the same category

1.Append Single data type values to a StringBuilder object.
2.Generic and nongeneric versions of the CompareTo method for Single value
3.Use the Sign(Single) method to determine the sign of a Single value and display it to the console.
4.Single value parse: NumberStyles.AllowParentheses
5.Single.Epsilon Field represents the smallest positive Single value that is greater than zero
6.Single.Equals returns a value indicating whether this instance is equal to a specified object.
7.Single.Parse Method converts string to single-precision floating-point number
8.Single.Parse converts string in a style to its single-precision floating-point number
9.Single.Parse Method converts string in a style and culture-specific format to single-precision floating-point number
10.Single.ToString converts value to string using the specified culture-specific format information.
11.Single.ToString converts single value to string representation using the specified format.
12.Single.ToString converts this instance to string using the specified format and culture-specific format information.
13.Single value format: C
14.Single value format: E04
15.Single value format: F
16.Single value format: N
17.Single value format: P
18.Convert value read from console to Single value
19.Single.TryParse Method converts string to single-precision floating-point number
20.Display negative value using the invariant culture
21.Display negative value using the en-GB culture.
22.Display negative value using the de-DE culture.
23.Display positive value using the invariant culture.
24.Display positive value using the en-GB culture.
25.Display positive value using the de-DE culture.