float

Type Range Default Value
float -3.402823e38 to 3.402823e38 0

The float type represents a single-precision floating-point number based on the IEEE-754 standard.

Literals

Integrals without a suffix are interpreted in this order: int, unsigned int, long, unsigned long, byte, signed byte, short, unsigned short, and char.

In order to denote a numeric value as a float, it is necessary to use a suffix. The suffixes for the float type are F and f.

Emulation

The float type is emulated in JS++ if JavaScript is the compilation target. This can be a source for performance slowdowns, and this type should therefore be used sparingly. Nevertheless, the float type is necessary; for example, it can be necessary for compatibility with SQL datatypes which also provide IEEE-754 single-precision floating-point numbers.

Auto-boxing

All primitive types have a corresponding wrapper class. The corresponding wrapper class for the float type is System.Float.

Auto-boxing occurs when a value of a primitive type is assigned or passed as an argument to a variable or function that expects a value of its corresponding wrapper class. For example, the numeric value 1.0f is interpreted as float and can be assigned to a variable of type System.Float via auto-boxing:

1
System.Float value = 1.0f; // Auto-boxing

Without auto-boxing, the equivalent code would be:

1
System.Float value = new System.Float(1.0f);

The reverse also occurs. Unboxing is when the wrapper class is automatically converted to its corresponding primitive type. Thus, an instance of System.Float can be unboxed to the float primitive type.

1
float value = new System.Float(1.0f); // Unboxing

Conversions

For conversions to and from the float type, consult the Conversions Table.

See Also

Share

HTML | BBCode | Direct Link