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
+5.8k nginx : force all pages to be SSL
+5.2k Unix/Linux/MacOSx : How to remove an environment variable ?
+5.4k Golang : Detect words using using consecutive letters in a given string
+4.6k Fix Google Analytics Redundant Hostnames problem
+11.1k Golang : Byte format example
+6.5k Golang : When to use make or new?
+9.9k Golang : How to get quoted string into another string?
+15.5k Golang : How to login and logout with JWT example
+30.2k Golang : Generate random string
+16.9k Golang : Find file size(disk usage) with filepath.Walk
+24.8k Golang : Create PDF file from HTML file
+14.1k Android Studio : Use image as AlertDialog title with custom layout example