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.4k Golang : Warp text string by number of characters or runes example
+18.4k Golang : Implement getters and setters
+14.5k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+18.9k Golang : Populate dropdown with html/template example
+12.2k Golang : Forwarding a local port to a remote server example
+29k Golang : Record voice(audio) from microphone to .WAV file
+5.6k Cash Flow : 50 days to pay your credit card debt
+10.3k Golang : Allow Cross-Origin Resource Sharing request
+13.9k Golang : Chunk split or divide a string into smaller chunk example
+11k Golang : How to pipe input data to executing child process?
+12k Golang : Flush and close file created by os.Create and bufio.NewWriter example