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
+6.8k Golang : Number guessing game with user input verification example
+26k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+23k Golang : Convert IP address string to long ( unsigned 32-bit integer )
+13.5k Golang : Get timezone offset from date or timestamp
+6.9k Golang : Metaprogramming example of wrapping a function
+10.1k Golang : Detect user location with HTML5 geo-location
+16.7k Golang : Logging with logrus
+15.4k Golang : How to make a file read only and set it to writable again?
+5.4k Golang : Warp text string by number of characters or runes example
+8.5k Android Studio : Simple input textbox and intercept key example
+5.8k Web : How to see your website from different countries?
+10.7k Golang : calculate elapsed run time