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
+42.4k Golang : Use wildcard patterns with filepath.Glob() example
+11.3k Swift : Convert (cast) Int or int32 value to CGFloat
+12.4k Golang : Reverse IP address for reverse DNS lookup example
+4.5k Golang : What is StructTag and how to get StructTag's value?
+9.3k Golang : Underscore string example
+9.8k Android Studio : Create custom icons for your application example
+5k Golang : Convert Chinese UTF8 characters to Pin Yin
+4.5k Golang : Display advertisement images or strings on random order
+18.9k Golang : How to force compile or remove object files first before rebuild?
+38k Golang : UDP client server read write example
+5.8k Golang : Decode XML data from RSS feed
+15.3k Golang : How to implement two-factor authentication?