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
+17.4k Golang : Display list of time zones with GMT
+6.1k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+10.3k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+6.3k Nginx : How to block user agent ?
+40k Golang : How to check if a string contains another sub-string?
+47.3k Golang : Upload file from web browser to server
+16.5k Golang : Qt image viewer example
+15.7k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+4.2k HTTP common errors and their meaning explained
+11.4k Golang : Get month name from date example
+8.2k Golang : Generate EAN barcode