System.Single Structure

Represents a single-precision floating-point number.

The System.Single value type represents a 32-bit floating-point number. It maps to the C# float keyword.

Namespace

System

Assembly

System.Runtime.dll

PropertyTypeDescription
MaxValuefloatThe largest possible value of a Single.
MinValuefloatThe smallest possible value of a Single.
EpsilonfloatThe smallest positive Single value that is greater than zero.
NaNfloatRepresents not a number.
NegativeInfinityfloatRepresents negative infinity.
PositiveInfinityfloatRepresents positive infinity.
  • CompareTo(Object) – Compares this instance to a specified object and returns an indication of their relative values.
  • CompareTo(Single) – Compares this instance to a specified Single value and returns an indication of their relative values.
  • Equals(Object) – Returns a value indicating whether this instance is equal to a specified object.
  • Equals(Single) – Returns a value indicating whether this instance is equal to a specified Single value.
  • GetHashCode() – Returns the hash code for this instance.
  • Parse(String) – Converts the string representation of a number to its single-precision floating-point number equivalent.
  • TryParse(String, out Single) – Tries to convert the string representation of a number to its single-precision floating-point number equivalent and returns a boolean that indicates success.
  • ToString() – Returns the string representation of the current number.

Basic usage

float temperature = 23.5f;
Console.WriteLine($"Temperature: {temperature} °C");

Parsing a string

string input = "3.14159";
if (float.TryParse(input, out float result))
{
    Console.WriteLine($"Parsed value: {result}");
}
else
{
    Console.WriteLine("Invalid number");
}