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
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+11.7k Golang : Display a text file line by line with line number example
+7.3k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+22.7k Golang : Strings to lowercase and uppercase example
+7.7k Golang : How to execute code at certain day, hour and minute?
+11.6k Swift : Convert (cast) Float to String
+9.8k Golang : Format strings to SEO friendly URL example
+15.7k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+7.9k Golang : Lock executable to a specific machine with unique hash of the machine
+10.5k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+11.6k Android Studio : Create custom icons for your application example
+10.2k Golang : Use regular expression to get all upper case or lower case characters example