C# Convert ToSingle(Object, IFormatProvider)

Description

Convert ToSingle(Object, IFormatProvider) converts the value of the specified object to an single-precision floating-point number, using the specified culture-specific formatting information.

Syntax

Convert.ToSingle(Object, IFormatProvider) has the following syntax.


public static float ToSingle(
  Object value,
  IFormatProvider provider
)

Parameters

Convert.ToSingle(Object, IFormatProvider) has the following parameters.

  • value - An object that implements the IConvertible interface.
  • provider - An object that supplies culture-specific formatting information.

Returns

Convert.ToSingle(Object, IFormatProvider) method returns A single-precision floating-point number that is equivalent to value, or zero if value is null.

Example


using System;//ww  w.  j  a va 2 s.  com
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((object) "12345" ));
        Console.WriteLine( Convert.ToSingle((object) "12345", provider ) );
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version