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
+6.1k Golang : Function as an argument type example
+12.9k Swift : Convert (cast) Int or int32 value to CGFloat
+14.7k Golang : Overwrite previous output with count down timer
+9.2k Golang : Simple histogram example
+10.1k Golang : Setting variable value with ldflags
+7.1k Golang : constant 20013 overflows byte error message
+9.5k Golang : Scramble and unscramble text message by randomly replacing words
+19.4k Golang : Display list of time zones with GMT
+20.4k Golang : How to get own program name during runtime ?
+36.7k Golang : Validate IP address
+14k Golang : Gin framework accept query string by post request example
+8.9k Yum Error: no such table: packages