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
+20.9k Golang : How to get time zone and load different time zone?
+9.2k Golang : Qt Yes No and Quit message box example
+45.7k Golang : Read tab delimited file with encoding/csv package
+30.5k Golang : Interpolating or substituting variables in string examples
+9.1k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+7.6k Golang : Scan files for certain pattern and rename part of the files
+11.4k SSL : The certificate is not trusted because no issuer chain was provided
+18.2k Golang : Logging with logrus
+6.3k Golang : Combine slices of complex numbers and operation example
+6.9k Golang : Squaring elements in array
+25.1k Golang : Daemonizing a simple web server process example
+13.2k Golang : Get constant name from value