Golang flag.Float64Var() function example

package flag

Float64Var defines a float64 flag with specified name(2nd parameter), default value(3rd parameter), and usage(4th parameter) string. The argument p(1st parameter) points to a float64 variable in which to store the value of the flag.

Golang flag.Float64Var() function usage example

 package main

 import (
 "flag"
 "fmt"
 )

 var boostvalue float64

 func init() {
 flag.Float64Var(&boostvalue, "throttle", 0.2, "Value to boost current throttle [default :0.2]")
 }

 func main() {
 fmt.Println(flag.Lookup("throttle")) // print Flag struct

 fmt.Printf("%.6f\n", boostvalue)
 }

Output :

&{throttle Value to boost current throttle [default :0.2] 0.2 0.2}

0.200000

Reference :

http://golang.org/pkg/flag/#Float64Var

Advertisement