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
+20.9k Golang : How to force compile or remove object files first before rebuild?
+10k Golang : Detect number of faces or vehicles in a photo
+23.8k Golang : Upload to S3 with official aws-sdk-go package
+41.2k Golang : Convert string to array/slice
+15.5k Golang : Get digits from integer before and after given position example
+8.9k Golang : Simple histogram example
+47.3k Golang : Convert int to byte array([]byte)
+21.2k Golang : How to read float value from standard input ?
+12.7k Golang : Convert IPv4 address to packed 32-bit binary format
+4.7k HTTP common errors and their meaning explained
+16.6k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+7.2k Android Studio : How to detect camera, activate and capture example