# float (C# Reference)

### In this article

The `float`

keyword signifies a simple type that stores 32-bit floating-point values. The following table shows the precision and approximate range for the `float`

type.

Type | Approximate range | Precision | .NET type |
---|---|---|---|

`float` |
±1.5 x 10^{−45} to ±3.4 x 10^{38} |
~6-9 digits | System.Single |

## Literals

By default, a real numeric literal on the right side of the assignment operator is treated as double. Therefore, to initialize a float variable, use the suffix `f`

or `F`

, as in the following example:

```
float x = 3.5F;
```

If you do not use the suffix in the previous declaration, you will get a compilation error because you are trying to store a double value into a `float`

variable.

## Conversions

You can mix numeric integral types and floating-point types in an expression. In this case, the integral types are converted to floating-point types. The evaluation of the expression is performed according to the following rules:

If one of the floating-point types is double, the expression evaluates to double, or to bool in relational comparisons or comparisons for equality.

If there is no double type in the expression, the expression evaluates to

`float`

, or to bool in relational comparisons or comparisons for equality.

A floating-point expression can contain the following sets of values:

Positive and negative zero

Positive and negative infinity

Not-a-Number value (NaN)

The finite set of nonzero values

For more information about these values, see IEEE Standard for Binary Floating-Point Arithmetic, available on the IEEE website.

## Example

In the following example, an int, a short, and a `float`

are included in a mathematical expression giving a `float`

result. (Remember that `float`

is an alias for the System.Single type.) Notice that there is no double in the expression.

```
class FloatTest
{
static void Main()
{
int x = 3;
float y = 4.5f;
short z = 5;
var result = x * y / z;
Console.WriteLine("The result is {0}", result);
Type type = result.GetType();
Console.WriteLine("result is of type {0}", type.ToString());
}
}
/* Output:
The result is 2.7
result is of type System.Single //'float' is alias for 'Single'
*/
```

## C# language specification

For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

## See also

## Feedback

Send feedback about:

Loading feedback...