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
+4.7k Swift : Get substring with rangeOfString() function example
+15.9k Golang : Get future or past hours, minutes or seconds
+18.2k Golang : Example for DSA(Digital Signature Algorithm) package functions
+10.6k Golang : Handle API query by curl with Gorilla Queries example
+18.6k Golang : Set or Add HTTP Request Headers
+5.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+20.6k Golang : How to reverse slice or array elements order
+8.4k Golang : Get all countries currencies code in JSON format
+48.7k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+7.5k Golang : Another camera capture GUI application with GTK and OpenCV
+11.2k Golang : How to check if a string starts or ends with certain characters or words?
+8.3k Golang : Find correlation coefficient example