Golang : convert(cast) float to string
This is an add-on to this previous tutorial on converting/casting int to string. To convert or cast a float value to string, just use the strconv.FormatFloat function.
package main
import "fmt"
import "strconv"
func main() {
str := strconv.FormatFloat(12342323.234232, 'f', 6, 64)
fmt.Println(str)
}
Reference :
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
+14.8k nginx: [emerg] unknown directive "ssl"
+6.8k Nginx : How to block user agent ?
+12.1k Golang : "https://" not allowed in import path
+19.5k Golang : Convert seconds to human readable time format example
+21.4k Golang : Use TLS version 1.2 and enforce server security configuration over client
+9.1k Golang : Extract or copy items from map based on value
+18.6k Golang : Clearing slice
+10.5k Golang : Sieve of Eratosthenes algorithm
+11.8k Golang : How to check if a string starts or ends with certain characters or words?
+9.4k PHP : Get coordinates latitude/longitude from string
+38.6k Golang : How to read CSV file
+20k Golang : Pipe output from one os.Exec(shell command) to another command