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
+16.9k Golang : Get input from keyboard
+4.7k Which content-type(MIME type) to use for JSON data
+36.5k Golang : Display float in 2 decimal points and rounding up or down
+9.7k Golang : Turn string or text file into slice example
+8.7k Yum Error: no such table: packages
+10.1k Golang : Use regular expression to get all upper case or lower case characters example
+13.5k Golang : Set image canvas or background to transparent
+24.4k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+19.1k Golang : Delete item from slice based on index/key position
+33.7k Golang : convert(cast) bytes to string
+7k Restart Apache or Nginx web server without password prompt