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
+4.8k Linux : Disable and enable IPv4 forwarding
+9.6k Golang : Get UDP client IP address and differentiate clients by port number
+12.8k Golang : Chunk split or divide a string into smaller chunk example
+12.8k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+3.9k Which content-type(MIME type) to use for JSON data
+4.4k Golang : Return multiple values from function
+5.3k Golang : How to get capacity of a slice or array?
+8.3k Golang : Terminate-stay-resident or daemonize your program?
+4.7k Javascript : How to refresh page with JQuery ?
+9.6k Golang : Command line file upload program to server example
+7.9k Golang : Take screen shot of browser with JQuery example
+3.2k Javascript : Empty an array example