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
+11.4k Golang : zlib compress file example
+15.4k Golang : Gzip file example
+37.8k Golang : Remove dashes(or any character) from string
+18k Golang : How to run your code only once with sync.Once object
+10.5k Golang : Find and draw contours with OpenCV example
+7.3k Android Studio : Image button and button example
+8.2k Golang : Web(Javascript) to server-side websocket example
+10.3k Golang : How to flush a channel before the end of program?
+15.9k Golang : Get future or past hours, minutes or seconds
+7.1k Golang : Reverse text lines or flip line order example
+15.4k CodeIgniter/PHP : Create directory if does not exist example