Skip to main content
The float keyword in C# represents a single-precision, 32-bit floating-point value type. It is an alias for the .NET System.Single struct and conforms to the IEEE 754 standard for binary floating-point arithmetic.

Technical Specifications

  • Underlying Type: System.Single
  • Memory Size: 4 bytes (32 bits)
  • Precision: ~6 to 9 significant decimal digits
  • Approximate Range: ±1.5 x 10^−45 to ±3.4 x 10^38
  • Default Value: 0.0f

Memory Layout

The 32 bits of a float are divided into three components according to IEEE 754:
  1. Sign bit: 1 bit (0 for positive, 1 for negative)
  2. Exponent: 8 bits (biased by 127)
  3. Mantissa (Significand): 23 bits (representing the fractional part)

Syntax and Initialization

By default, a real numeric literal on the right side of an assignment is treated as a double. To initialize a float, you must append the literal suffix f or F. Omitting the suffix results in a compiler error due to the lack of an implicit conversion from double to float.

Special Values

The System.Single struct provides constants to represent special floating-point states that occur during undefined or overflow arithmetic operations.

Type Conversions

Implicit Conversions: C# allows implicit conversions to float from any integral type (sbyte, byte, short, ushort, int, uint, long, ulong, and char). Note that converting from 32-bit or 64-bit integers (int, long) to float may result in a loss of precision, though the magnitude is preserved.
Explicit Conversions: Conversions from higher-precision floating-point types (double, decimal) to float require an explicit cast. This can result in overflow (yielding infinity) or a loss of precision.
Tired of Poor C# Skills? Fix That With Deep Grasping!Learn More