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
+29.2k Golang : Get first few and last few characters from string
+9.6k Golang : Extract or copy items from map based on value
+17k Golang : How to generate QR codes?
+19.4k Golang : Get RGBA values of each image pixel
+20.5k Golang : Check if os.Stdin input data is piped or from terminal
+5k JQuery : Calling a function inside Jquery(document) block
+4.2k Javascript : Empty an array example
+32.6k Golang : Math pow(the power of x^y) example
+4.8k Unix/Linux : How to pipe/save output of a command to file?
+19.1k Golang : Clearing slice
+5.4k Javascript : Shuffle or randomize array example