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
+5.7k Golang : Get Alexa ranking data example
+3.5k Golang : Experimental Jawi programming language
+7.3k Golang : Combine slices but preserve order example
+5.2k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+16.4k Golang : Iterating Elements Over A List
+18.3k nginx: [emerg] unknown directive "passenger_enabled"
+4.9k Golang & Javascript : How to save cropped image to file on server
+5.9k Golang : Process json data with Jason package
+7.5k Golang : Heap sort example
+28.2k Get client IP Address in Go
+5.3k Golang : Calculate diameter, circumference, area, sphere surface and volume