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
+21.1k Golang : Read a file into an array or slice example
+7.7k Golang : Gorilla web tool kit schema example
+20.9k Golang : Read directory content with filepath.Walk()
+17.3k Golang : Get path name to current directory or folder
+6.3k Golang : Dealing with postal or zip code example
+6.8k Golang : Error reading timestamp with GORM or SQL driver
+14.5k Golang : Loop each day of the current month example
+4.7k Swift : Get substring with rangeOfString() function example
+17.7k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+32.6k Golang : Proper way to set function argument default value
+5.9k Golang : Calculate BMI and risk category
+10k Golang : Create S3 bucket with official aws-sdk-go package