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
+26.5k Golang : Calculate future date with time.Add() function
+15.7k Golang : How to convert(cast) IP address to string?
+9.7k Golang : Read file with ioutil
+22.4k Golang : Securing password with salt
+14.2k Golang : Google Drive API upload and rename example
+8k Golang : Load DSA public key from file example
+41.6k Golang : Convert string to array/slice
+5.5k Gogland : Datasource explorer
+5.3k Responsive Google Adsense
+10.3k Golang : Find and replace data in all files recursively
+5.9k Linux/Unix/PHP : Restart PHP-FPM
+7.6k Golang : Handling Yes No Quit query input