C# Single Parse(String, IFormatProvider)
Description
Single Parse(String, IFormatProvider)
converts the
string representation of a number in a specified culture-specific format
to its single-precision floating-point number equivalent.
Syntax
Single.Parse(String, IFormatProvider)
has the following syntax.
public static float Parse(
string s,
IFormatProvider provider
)
Parameters
Single.Parse(String, IFormatProvider)
has the following parameters.
s
- A string that contains a number to convert.provider
- An object that supplies culture-specific formatting information about s.
Returns
Single.Parse(String, IFormatProvider)
method returns A single-precision floating-point number equivalent to the numeric value
or symbol specified in s.
Example
The following example uses Single.Parse(String, IFormatProvider)
method.
using System.Globalization;
using System;/* www . j a v a 2 s . c o m*/
public class MainClass
{
public static void Main(String[] argv)
{
float number;
// Convert user input from a string to a number
number = Single.Parse("123", CultureInfo.InvariantCulture.NumberFormat);
}
}
The code above generates the following result.