# FloatToHalf(float)

> Encode a floating point value into a 16-bit representation.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public static ushort FloatToHalf(float val)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The floating point value to convert.

### Returns

| Type                                                           | Description                                                              |
| -------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [ushort](https://learn.microsoft.com/dotnet/api/system.uint16) | The converted half-precision float, stored in a 16-bit unsigned integer. |

### Remarks

Converting a floating point value to a half causes it to lose precision and also reduces the maximum range of values it can represent. The new range is from -65,504 and 65,504. For more information on 16-bit floating-point numbers, and for information on how precision changes over the range of values, see Half-precision floating-point format.

If the converted floating point value falls exactly between two half-precision values, this method rounds it to the value furthest from zero (Round away from zero tie-break rule). This selects the value closer to positive or negative infinity, depending on the sign.

You should only use the returned ushort as a storage format. If you want to perform mathematical operations on it, first convert it back to a float with [Mathf.HalfToFloat](/engine/6000.0/script-reference/unityengine/mathf/halftofloat.md).
