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
+29.6k error: trying to remove "yum", which is protected
+7.4k Golang : Convert word to its plural form example
+16.4k How to enable MariaDB/MySQL logs ?
+23.1k Golang : Time slice or date sort and reverse sort example
+4.1k Golang : micron to centimeter example
+7.6k Golang : Gaussian blur on image and camera video feed examples
+18.3k Golang : Check if os.Stdin input data is piped or from terminal
+11.3k Golang : Sort and reverse sort a slice of bytes
+10.7k Golang : Clean formatting/indenting or pretty print JSON result
+7.7k Golang : Gorilla web tool kit schema example
+6.1k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+26.8k Golang : Read, Write(Create) and Delete Cookie example