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
+16.1k Golang : When to use init() function?
+7.2k Your page has meta tags in the body instead of the head
+4k HTTP common errors and their meaning explained
+14.2k Golang : Get current time from the Internet time server(ntp) example
+3.1k Detect if Google Analytics and Developer Media are loaded properly or not
+9.1k Golang : Wait and sync.WaitGroup example
+6.2k Golang : Example of custom handler for Gorilla's Path usage.
+3.8k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+17.7k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+6.8k Javascript : Put image into Chrome browser's console
+4.7k Golang : Markov chains to predict probability of next state example
+40.2k Golang : Convert string to array/slice