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
+9.8k Random number generation with crypto/rand in Go
+6.7k Golang : Experimental emojis or emoticons icons programming language
+17.8k Golang : Iterate linked list example
+18k Golang : How to log each HTTP request to your web server?
+33k Golang : How to check if a date is within certain range?
+11.3k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+9.8k Golang : List available AWS regions
+7.8k Golang : Regular Expression find string example
+20.7k Golang : Saving private and public key to files
+14k Golang : Google Drive API upload and rename example
+20.2k Golang : Convert seconds to human readable time format example
+6.1k nginx : force all pages to be SSL