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
+17.1k Golang : How to get hour, minute, second from time?
+21k Golang : Repeat a character by multiple of x factor
+7k Golang : Multiplexer with net/http and map
+8.7k Golang : Bcrypting password
+12.9k Golang : Convert IP version 6 address to integer or decimal number
+21.1k Golang : untar or extract tar ball archive example
+9.8k Golang : Natural string sorting example
+20.8k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+3.8k Nginx and PageSpeed build from source CentOS example
+14.6k Golang : Update database with GORM example
+12.8k Golang : Check if a file exist or not
+16k Golang : How to save log messages to file?