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
+10.1k Golang : Find age or leap age from date of birth example
+12k Golang : Image to ASCII art example
+9.4k Golang : Simple File Server
+11.7k Golang : Convert(cast) uintptr to string example
+21.1k Golang : Set and Get HTTP request headers example
+8.4k Golang : Format strings to SEO friendly URL example
+3.9k Unix/Linux : How to pipe/save output of a command to file?
+6.5k SSL : How to check if current certificate is sha1 or sha2 from command line
+22.3k Golang : Check if element exist in map
+4.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+18.3k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader