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.6k Unix/Linux/MacOSx : How to remove an environment variable ?
+9.5k Golang : Terminate-stay-resident or daemonize your program?
+10.4k Golang : Check a web page existence with HEAD request example
+5.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+5.4k JavaScript/JQuery : Redirect page examples
+7.5k Golang : File system scanning
+11.4k Golang : How to determine a prime number?
+11.7k Swift : Convert (cast) Float to String
+19.1k Golang : Read input from console line
+27.7k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+12.5k Golang : List running EC2 instances and descriptions