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.7k Restart Apache or Nginx web server without password prompt
+18.2k Golang : Delete item from slice based on index/key position
+25.1k Golang : Encrypt and decrypt data with AES crypto
+5.8k Golang : Pat multiplexer routing example
+6.7k Golang : Reverse a string with unicode
+8.6k Golang : Populate slice with sequential integers example
+19k Golang : How to force compile or remove object files first before rebuild?
+6.3k Golang : alternative to os.Exit() function
+4.4k Golang : If else example and common mistake
+6.2k Golang : Gorrila mux.Vars() function example
+6.3k Golang : Getting Echo framework StartAutoTLS to work