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
| Property | Type | Description |
|---|---|---|
| MaxValue | float | The largest possible value of a Single. |
| MinValue | float | The smallest possible value of a Single. |
| Epsilon | float | The smallest positive Single value that is greater than zero. |
| NaN | float | Represents not a number. |
| NegativeInfinity | float | Represents negative infinity. |
| PositiveInfinity | float | Represents 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
Singlevalue 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
Singlevalue. - 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");
}