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
+8.7k Golang : Set or add headers for many or different handlers
+12.4k Golang : Print UTF-8 fonts on image example
+12.5k Golang : 2 dimensional array example
+17.1k Golang : How to save log messages to file?
+18.7k Golang : Send email with attachment
+9.5k Golang : Timeout example
+8.4k Useful methods to access blocked websites
+6.2k Java : Human readable password generator
+10.7k Golang : Get local time and equivalent time in different time zone
+21.8k Golang : GORM create record or insert new record into database example
+11.4k Golang : How to use if, eq and print properly in html template