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
+6.3k Golang : Detect face in uploaded photo like GPlus
+6k Golang : Debug with Godebug
+15k Golang : package is not in GOROOT during compilation
+36.6k Golang : Display float in 2 decimal points and rounding up or down
+11.9k Golang : Determine if time variables have same calendar day
+13.1k Golang : How to get a user home directory path?
+28.7k Golang : Detect (OS) Operating System
+13.5k Golang : Query string with space symbol %20 in between
+10.6k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+30.5k Golang : Remove characters from string example
+21.8k Golang : Use TLS version 1.2 and enforce server security configuration over client
+10.4k Fix ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)