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
+7.4k Golang : On lambda, anonymous, inline functions and function literals
+9.3k Golang : Generate random integer or float number
+10.5k Golang : Get remaining text such as id or filename after last segment in URL path
+5.5k Nginx : Password protect a directory/folder
+24.2k Golang : How to read integer value from standard input ?
+9.4k Golang : Underscore string example
+50.5k Golang : How to get time in milliseconds?
+3.9k PHP : Extract part of a string starting from the middle
+7.5k Golang : How to join strings?
+4.5k Javascript : Shuffle or randomize array example
+10.7k Golang : Detect user location with HTML5 geo-location