Golang : convert(cast) string to float value
To convert or cast a string to float value, just use the strconv.ParseFloat()
function. Below is the code example to demonstrate how to convert string to float64 value.
package main
import (
"fmt"
"strconv"
)
func main() {
var floatvalue float64
floatvalue, _ = strconv.ParseFloat("123.456", 64)
fmt.Println(floatvalue)
}
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
+22.7k Golang : Test file read write permission example
+6.8k Golang : Levenshtein distance example
+10.7k Golang : How to transmit update file to client by HTTP request example
+5.4k Python : Print unicode escape characters and string
+7k Golang : Null and nil value
+12.1k Golang : How to check if a string starts or ends with certain characters or words?
+15.2k Golang : invalid character ',' looking for beginning of value
+10k Golang : Check a web page existence with HEAD request example
+22.7k Golang : Gorilla mux routing example
+11.3k Golang : Generate DSA private, public key and PEM files example
+5.5k Golang : Shortening import identifier
+18.8k Golang : Check whether a network interface is up on your machine