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
+14.9k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+5.4k Golang : Qt splash screen with delay example
+11k Golang : Loop each day of the current month example
+2.9k JavaScript: Add marker function on Google Map
+8.2k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+6.9k Golang : Generate random elements without repetition or duplicate
+3.5k Golang : Display advertisement images or strings on random order
+7.9k Golang : How to pass map to html template and access the map's elements
+17.4k Golang : Randomly pick an item from a slice/array example
+6.7k Golang : Check if user agent is a robot or crawler example
+8.7k Golang : md5 hash of a string
+3.2k Python : Convert(cast) string to bytes example