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
+7.6k Golang : How to handle file size larger than available memory panic issue
+8.5k Golang : Generate Datamatrix barcode
+5.8k Get website traffic ranking with Similar Web or Alexa
+7.7k Javascript : Push notifications to browser with Push.js
+21.3k Golang : Create and resolve(read) symbolic links
+9.9k Golang : Get current, epoch time and display by year, month and day
+6.7k Golang : Skip or discard items of non-interest when iterating example
+7.3k Golang : How to iterate a slice without using for loop?
+16.1k Golang : Get sub string example
+9.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+8.8k Golang : Take screen shot of browser with JQuery example
+7.7k Android Studio : AlertDialog to get user attention example