Standard library / reflect

reflect.Value.SetFloat()

Change a settable float32 value through its kind-specific setter. Wrong kinds or non-settable values panic; numeric conversions may narrow. Expected stdout: '1.5\n'.

Formal Syntax & Structure

go syntaxgo
func (v Value) SetFloat(x float64)

Parameters & Attributes

NameTypeDescription
xfloat64New value; must satisfy the destination kind or assignability requirement.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { var x float32; reflect.ValueOf(&x).Elem().SetFloat(1.5); fmt.Println(x) }
Go Reference