# GetFloat

> Returns the float value corresponding to key if it exists in the preference file.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.7/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

## GetFloat(string, float)

Returns the float value corresponding to `key` if it exists in the preference file.

```csharp
public static float GetFloat(string key, float defaultValue)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name of key to read float from.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Float value to return if the key is not in the storage.

### Returns

| Type                                                          | Description                                                                                              |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| [float](https://learn.microsoft.com/dotnet/api/system.single) | The float value stored in the preference file or the defaultValue id the requested float does not exist. |

### Remarks

If `GetFloat` does not exist in the Preference file the `defaultValue` will be returned.

### Examples

```csharp
// Simple script that allows a float value to be editted
// in a slider. The start value is selected from the Editor Preferences.

using UnityEngine;
using UnityEditor;
using System;

public class SetFloatExample : EditorWindow
{
    static float floatValue = 0.0f;

    [MenuItem("Examples/Preferences SetFloat Example")]
    static void Init()
    {
        Rect r = new Rect(10, 10, 200, 100);
        SetFloatExample window = (SetFloatExample)EditorWindow.GetWindowWithRect(typeof(SetFloatExample), r);
        window.Show();
    }

    void Awake()
    {
        floatValue = EditorPrefs.GetFloat("FloatExample", floatValue);
    }

    void OnGUI()
    {
        floatValue = EditorGUILayout.Slider(floatValue, -1.0f, 1.0f);
        if (GUILayout.Button("Save float " + Convert.ToString(floatValue) + "?"))
        {
            EditorPrefs.SetFloat("FloatExample", floatValue);
        }
        if (GUILayout.Button("Close"))
            this.Close();
    }
}
```

## GetFloat(string)

Returns the float value corresponding to `key` if it exists in the preference file.

```csharp
public static float GetFloat(string key)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name of key to read float from.

### Returns

| Type                                                          | Description                                                                                              |
| ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| [float](https://learn.microsoft.com/dotnet/api/system.single) | The float value stored in the preference file or the defaultValue id the requested float does not exist. |

### Remarks

If `GetFloat` does not exist in the Preference file the `defaultValue` will be returned.

### Examples

```csharp
// Simple script that allows a float value to be editted
// in a slider. The start value is selected from the Editor Preferences.

using UnityEngine;
using UnityEditor;
using System;

public class SetFloatExample : EditorWindow
{
    static float floatValue = 0.0f;

    [MenuItem("Examples/Preferences SetFloat Example")]
    static void Init()
    {
        Rect r = new Rect(10, 10, 200, 100);
        SetFloatExample window = (SetFloatExample)EditorWindow.GetWindowWithRect(typeof(SetFloatExample), r);
        window.Show();
    }

    void Awake()
    {
        floatValue = EditorPrefs.GetFloat("FloatExample", floatValue);
    }

    void OnGUI()
    {
        floatValue = EditorGUILayout.Slider(floatValue, -1.0f, 1.0f);
        if (GUILayout.Button("Save float " + Convert.ToString(floatValue) + "?"))
        {
            EditorPrefs.SetFloat("FloatExample", floatValue);
        }
        if (GUILayout.Button("Close"))
            this.Close();
    }
}
```
