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.5k JavaScript: Add marker function on Google Map
+11.7k Golang : Sort and reverse sort a slice of runes
+8k Golang : Check if integer is power of four example
+8.9k Golang : Write multiple lines or divide string into multiple lines
+11.8k Golang : Get remaining text such as id or filename after last segment in URL path
+41.2k Golang : Convert string to array/slice
+21.4k Golang : Convert string slice to struct and access with reflect example
+6.8k Restart Apache or Nginx web server without password prompt
+10.3k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+11.1k Golang : Byte format example
+12k Golang : Display list of countries and ISO codes
+9.4k Golang : Eroding and dilating image with OpenCV example