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.7k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+5.1k Golang : Debug with Godebug
+25.9k PHP : Count number of JSON items/objects
+8.9k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+11.6k Golang : Pass database connection to function called from another package and HTTP Handler
+10k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+16k Golang : How to make a file read only and set it to writable again?
+3.8k Linux/MacOSX : How to symlink a file?
+5k Golang : Extract unicode string from another unicode string example
+7.5k Golang : How to join strings?
+9.1k Golang : cannot assign type int to value (type uint8) in range error
+8k Golang : Serving HTTP and Websocket from different ports in a program example