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
+5k Golang : Detect variable or constant type
+10.4k Golang : Concurrency and goroutine example
+7.7k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+35k Golang : Display float in 2 decimal points and rounding up or down
+37.8k Golang : How to iterate over a []string(array)
+13.9k Golang : Find location by IP address and display with Google Map
+19.3k PHP : Convert(cast) int to double/float
+25.2k Golang : Find files by extension
+14.2k Golang : Delete certain files in a directory
+10.7k Golang : Split strings into command line arguments
+5.2k Golang : How to get capacity of a slice or array?
+5.1k AWS S3 : Prevent Hotlinking policy