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
+11.8k Golang : How to check if a string starts or ends with certain characters or words?
+16.5k Golang : XML to JSON example
+12.1k Golang : Add ASCII art to command line application launching process
+24.8k Golang : Get current file path of a file or executable
+7k Golang : Individual and total number of words counter example
+18k Golang : Read binary file into memory
+9.3k Random number generation with crypto/rand in Go
+5k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+16.8k Golang : When to use init() function?
+28.8k Golang : missing Git command
+22.6k Golang : Get ASCII code from a key press(cross-platform) example
+4.8k PHP : See installed compiled-in-modules