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
+11.9k Golang : Encrypt and decrypt data with x509 crypto
+16k Golang : Generate QR codes for Google Authenticator App and fix "Cannot interpret QR code" error
+19.6k Swift : Convert (cast) Int to int32 or Uint32
+5.6k Golang : Grab news article text and use NLP to get each paragraph's sentences
+20k Nginx + FastCGI + Go Setup.
+11.9k Golang : How to check if a string starts or ends with certain characters or words?
+4.5k Python : Find out the variable type and determine the type with simple test
+11.6k Golang : How to parse plain email text and process email header?
+16.3k Golang : Gzip file example
+47k Golang : Convert int to byte array([]byte)
+7k Golang : Create zip/ePub file without compression(use Store algorithm)
+10.8k CodeIgniter : How to check if a session exist in PHP?