# SetFloat(string, float)

> Sets the float value of the preference identified by key.

## Definition

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

```csharp
public static void SetFloat(string key, float value)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Name of key to write float into.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Float value to write into the storage.

### Examples

```csharp
// Simple script that allows a float value to be editted
// in a slider. The final value is written into 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();
    }
}
```
