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
+15.8k Golang : Get digits from integer before and after given position example
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+11.6k Golang : Find age or leap age from date of birth example
+22.6k Golang : Strings to lowercase and uppercase example
+13.3k Golang : Linear algebra and matrix calculation example
+12.2k Golang : calculate elapsed run time
+3.3k Golang : Fix go-cron set time not working issue
+9.3k Golang : Generate EAN barcode
+4.6k Adding Skype actions such as call and chat into web page examples
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+21.8k Golang : Convert string slice to struct and access with reflect example
+6.1k Golang : Scan forex opportunities by Bollinger bands