C# Convert ToSingle(String, IFormatProvider)
Description
Convert ToSingle(String, IFormatProvider)
converts
the specified string representation of a number to an equivalent single-precision
floating-point number, using the specified culture-specific formatting
information.
Syntax
Convert.ToSingle(String, IFormatProvider)
has the following syntax.
public static float ToSingle(
string value,
IFormatProvider provider
)
Parameters
Convert.ToSingle(String, IFormatProvider)
has the following parameters.
value
- A string that contains the number to convert.provider
- An object that supplies culture-specific formatting information.
Returns
Convert.ToSingle(String, IFormatProvider)
method returns A single-precision floating-point number that is equivalent to the number
in value, or 0 (zero) if value is null.
Example
using System;/*w ww .j av a2 s.c om*/
using System.Globalization;
class MainClass
{
public static void Main( )
{
NumberFormatInfo provider = new NumberFormatInfo();
provider.NegativeSign = "neg ";
provider.PositiveSign = "pos ";
provider.NumberDecimalSeparator = ".";
provider.NumberGroupSeparator = ",";
provider.NumberGroupSizes = new int[ ] { 3 };
provider.NumberNegativePattern = 0;
Console.WriteLine( Convert.ToSingle( "12345" ));
Console.WriteLine( Convert.ToSingle( "12345", provider ) );
}
}
The code above generates the following result.