Use strconv.FormatFloat like such:

s := strconv.FormatFloat(3.1415, 'f', -1, 64)
fmt.Println(s)

Outputs

3.1415

Answer from Ullaakut on Stack Overflow
🌐
YourBasic
yourbasic.org › golang › convert-string-to-float
Convert between float and string · YourBasic Go
CODE EXAMPLE Use strconv.ParseFloat to parse a floating point number from a string, and fmt.Sprintf to format a float as a string.
Discussions

Problem converting float32 to string
HI I have problem with float32 to string conversion. My test code: package main import ( "fmt" "strconv" ) func main() { var t float32 t = 5.9902389 numeroString := strconv.FormatFloat(float64(t), 'f', -1, 32) fmt.Println("Number float32:", t) fmt.Println("Number string:", numeroString) } Responce: ... More on forum.golangbridge.org
🌐 forum.golangbridge.org
1
0
July 20, 2023
Converting a float to string
http://golang.org/pkg/strconv/#FormatFloat http://golang.org/pkg/strconv/#ParseFloat If you don't care about errors, write a small wrapper func. More on reddit.com
🌐 r/golang
5
3
November 20, 2014
go - formatFloat : convert float number to string - Stack Overflow
How do I convert a float number into string format? This is google playground but not getting the expected output. More on stackoverflow.com
🌐 stackoverflow.com
go - Converting string input to float64 using ParseFloat in Golang - Stack Overflow
I've just started learning Go and I'm trying to convert a string from standard input to a float64 so I can perform an arithmetic operation on the input value. The output returns "0 feet converted to More on stackoverflow.com
🌐 stackoverflow.com
🌐
Educative
educative.io › answers › how-can-we-convert-a-float-into-a-string-in-golang
How can we convert a float into a string in Golang
A float can be converted into a string, in Golang, using the following two functions: FormatFloat: This function is available within the strconv package. Sprintf: This function is available within the fmt package.
🌐
Go Packages
pkg.go.dev › strconv
strconv package - strconv - Go Packages
FormatFloat converts the floating-point number f to a string, according to the format fmt and precision prec.
🌐
Go Forum
forum.golangbridge.org › getting help
Problem converting float32 to string - Getting Help - Go Forum
July 20, 2023 - My test code: package main import ( "fmt" "strconv" ) func main() { var t float32 t = 5.9902389 numeroString := strconv.FormatFloat(float64(t), 'f', -1, 32) fmt.Println("Number float32:", t) fmt.Println("Number string:", numeroString) } Responce: ...
🌐
Reddit
reddit.com › r/golang › converting a float to string
r/golang on Reddit: Converting a float to string
November 20, 2014 -

What is the easy way of converting a float to a string?

The strconv package seems awfully cluttered and there doesn't seem to be a function where you can simply give a float and get a string

🌐
Reintech
reintech.io › blog › introduction-to-gos-strconv-package-string-conversions
An Introduction to Go's `strconv` Package: String Conversions | Reintech media
January 26, 2026 - It takes three arguments: the floating-point number, the format ('f', 'b', 'e', or 'g'), and the precision (number of decimal points), and the number of bits the floating-point number occupies (32 or 64). It returns a string representation of the floating-point number. The strconv.Itoa() function in Go is used to convert an integer to a string.
🌐
GitHub
gist.github.com › morrxy › b5972d4516e1e41229aba77f85894942
[int float to string] #golang · GitHub
[int float to string] #golang · Raw · float2str.go · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Find elsewhere
🌐
Admfactory
admfactory.com › home › how to convert a float to string in golang
How to convert a float to string in Golang | ADMFactory
June 11, 2020 - package main import ( "fmt" "strconv" ) func main() { /** float variable */ f := 1.23456789 /** converting the f variable into a string */ /** 5 is the number of decimals */ /** 64 is for float64 type*/ str := strconv.FormatFloat(f, 'f', 5, 64) /** displaying the string variable into the console */ fmt.Println(str) } To compile the code navigate to the file location and run the following command.
🌐
Educative
educative.io › answers › how-to-convert-a-string-to-a-float-in-golang
How to convert a string to a float in Golang
If the input string is non-numeric, then this function will throw an invalid syntax error and the float value will be set to 0. The code snippet below shows how to convert a string to a float using the ParseFloat function.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-convert-data-types-in-go
How To Convert Data Types in Go | DigitalOcean
May 9, 2019 - Strings can be converted to numbers by using the strconv package in the Go standard library. The strconv package has functions for converting both integer and float number types. This is a very common operation when accepting input from the user. For example, if you had a program that asked ...
🌐
Python Examples
pythonexamples.org › go › how-to-convert-float-to-string
How to convert Float to String in Go
package main import ( "fmt" "strconv" ... declare a float variable float2 with a value of 10.5. We import the strconv package. We use the FormatFloat function to convert the float to a string and store the result in a variable str2....
🌐
TutorialKart
tutorialkart.com › golang-tutorial › golang-convert-string-to-float
How to convert String to Float in Go Language?
July 1, 2021 - In this tutorial, we will learn the syntax of ParseFloat() function, and how to use this function to parse or convert a string to float value.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-string-to-float-type-in-golang
How to Convert string to float type in Golang? - GeeksforGeeks
May 19, 2020 - In order to convert Boolean Type to String type in Golang , you can use the strconv and fmt package function. 1. strconv.FormatBool() Method: The FormatBool is used to Boolean Type to String.
🌐
php.cn
m.php.cn › home › backend development › golang › how to convert float to string type in go language
How to convert float to string type in go language-Golang-php.cn
January 17, 2023 - Conversion method: 1. Use the Sprintf() function, which supports converting float32 and float64 to string. The syntax is "str := fmt.Sprintf("%f", floatVar)".
🌐
Siongui
siongui.github.io › 2017 › 04 › 13 › go-string-float-number-type-casting
[Golang] Type Conversion between String and Floating Number
package main import ( "fmt" "strconv" ) func main() { width := "560" height := "315" // convert string to float64 w, err := strconv.ParseFloat(width, 64) if err != nil { fmt.Println(err) } h, err := strconv.ParseFloat(height, 64) if err != nil { fmt.Println(err) } // make calculation and then convert float64 to string aspectRatio := strconv.FormatFloat(h*100/w, 'f', -1, 64) + "%" fmt.Println("aspect ratio: ", aspectRatio) }