Golang : How to read float value from standard input ?
This is a continuation from previous tutorial on how to read integer value from standard input. For this tutorial, we will learn how to read float value from standard input. Below is the code to do that :
package main
import (
"fmt"
"strconv"
)
func main() {
var f float64
fmt.Println("Enter a float value : ")
_, err := fmt.Scanf("%f", &f)
if err != nil {
fmt.Println(err)
}
fmt.Printf("You have entered : %f \n", f)
fmt.Println("Alternative output ", strconv.FormatFloat(f, 'f', 6, 64))
}
See also : Golang : How to read integer value from standard input ?
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+17.5k Golang : Defer function inside init()
+30.6k Golang : Download file example
+5.2k Javascript : Change page title to get viewer attention
+14k Golang : Check if a file exist or not
+10.4k Golang : Select region of interest with mouse click and crop from image
+34.4k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+4.6k Linux/MacOSX : How to symlink a file?
+17.2k Golang : Check if IP address is version 4 or 6
+11.2k Golang : How to use if, eq and print properly in html template
+16.9k Golang : Covert map/slice/array to JSON or XML format
+24.3k Golang : Change file read or write permission example
+7k Golang : Transform lisp or spinal case to Pascal case example