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
+3.7k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+7.6k Golang : Random Rune generator
+23.1k Get file path of temporary file in Go
+15.4k Golang : Send email with attachment
+8.9k Golang : Detect user location with HTML5 geo-location
+34.6k Golang : Comparing date or timestamp
+5.1k Golang : Decode XML data from RSS feed
+38.8k Golang : How to check if a string contains another sub-string?
+3.7k Golang : Shortening import identifier
+19.4k Golang : Securing password with salt
+4.7k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+15.7k Golang : Check if os.Stdin input data is piped or from terminal