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
+12k Golang : Validate email address
+16.9k Golang : How to tell if a file is compressed either gzip or zip ?
+6.1k Golang : Detect face in uploaded photo like GPlus
+6.9k CloudFlare : Another way to get visitor's real IP address
+7.3k Golang : Convert(cast) io.Reader type to string
+9.9k Golang : Compare files modify date example
+7.3k SSL : How to check if current certificate is sha1 or sha2 from command line
+11.4k Golang : Gorilla web tool kit secure cookie example
+8.8k Golang : How to use Gorilla webtoolkit context package properly
+14.7k Golang : Save(pipe) HTTP response into a file
+7.8k Golang : Variadic function arguments sanity check example