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
🌐
Go Packages
pkg.go.dev › strconv
strconv package - strconv - Go Packages
Output: float32:3.1415927E+00 float64:3.1415926535E+00 ... AppendInt appends the string form of the integer i, as generated by FormatInt, to dst and returns the extended buffer. ... package main import ( "fmt" "strconv" ) func main() { b10 := []byte("int (base 10):") b10 = strconv.AppendInt(b10, -42, 10) fmt.Println(string(b10)) b16 := []byte("int (base 16):") b16 = strconv.AppendInt(b16, -42, 16) fmt.Println(string(b16)) }
Discussions

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. (2e+07) I want to get "21312421.213123" package main import "fmt" import "strconv" func floattostr(input_num float64) string { // to convert a float number to a string return ... 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
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
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
🌐
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.
🌐
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.
🌐
Educative
educative.io › answers › how-to-use-the-strconvformatfloat-function-in-golang
How to use the strconv.FormatFloat() function in Golang
The FormatFloat() function in the strconv package is used to convert a given floating-point number f to 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 ... representation of the floating-point number. The strconv.Itoa() function in Go is used to convert an integer to a string....
🌐
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 - If you need help how to install Golang check the references links. FormatFloat converts the floating-point number f to a string, according to the format fmt and precision prec. It rounds the result assuming that the original was obtained from ...
Find elsewhere
🌐
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.
🌐
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

🌐
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: ...
🌐
Educative
educative.io › answers › how-to-use-the-strconvparsefloat-function-in-golang
How to use the strconv.ParseFloat() function in Golang
The ParseFloat() function returns the floating-point number converted from the given string. The following code shows how to implement the strconv.ParseFloat() function in Golang:
Top answer
1 of 2
12

Package strconv

import "strconv" > func FormatFloat

func FormatFloat(f float64, fmt byte, prec, bitSize int) string

FormatFloat converts the floating-point number f to a string, according to the format fmt and precision prec. It rounds the result assuming that the original was obtained from a floating-point value of bitSize bits (32 for float32, 64 for float64).

The format fmt is one of 'b' (-ddddp±ddd, a binary exponent), 'e' (-d.dddde±dd, a decimal exponent), 'E' (-d.ddddE±dd, a decimal exponent), 'f' (-ddd.dddd, no exponent), 'g' ('e' for large exponents, 'f' otherwise), or 'G' ('E' for large exponents, 'f' otherwise).

The precision prec controls the number of digits (excluding the exponent) printed by the 'e', 'E', 'f', 'g', and 'G' formats. For 'e', 'E', and 'f' it is the number of digits after the decimal point. For 'g' and 'G' it is the total number of digits. The special precision -1 uses the smallest number of digits necessary such that ParseFloat will return f exactly.

Use a precision of -1, not 1. Use a format of f, not g to avoid exponent form for large exponents (see HectorJ's comment).

startLat := strconv.FormatFloat(o.Coordinate.Longitude, 'f', -1, 64)

For example,

package main

import (
    "fmt"
    "strconv"
)

func main() {
    f := 64.2345
    s := strconv.FormatFloat(f, 'g', 1, 64)
    fmt.Println(s)
    s = strconv.FormatFloat(f, 'f', -1, 64)
    fmt.Println(s)
}

Output:

6e+01
64.2345
2 of 2
0

Some other options:

package main
import "fmt"

func main() {
   n := 64.2345
   { // example 1
      s := fmt.Sprint(n)
      fmt.Println(s == "64.2345")
   }
   { // example 2
      s := fmt.Sprintf("%v", n)
      fmt.Println(s == "64.2345")
   }
   { // example 3
      s := fmt.Sprintf("%g", n)
      fmt.Println(s == "64.2345")
   }
}
  • https://golang.org/pkg/fmt#Sprint
  • https://golang.org/pkg/fmt#Sprintf
🌐
Linux Hint
linuxhint.com › string-float-golang
Golang String to Float
February 11, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Go Packages
pkg.go.dev › cuelang.org › go › pkg › strconv
strconv package - cuelang.org/go/pkg/strconv - Go Packages
March 3, 2026 - FormatFloat converts the floating-point number f to a string, according to the format fmt and precision prec.
🌐
ZetCode
zetcode.com › golang › strconv-formatfloat
Using strconv.FormatFloat in Go
April 20, 2025 - We convert the float 123.456 to a string using 'f' format. The precision -1 means use the smallest number of digits necessary. 64 specifies float64 type. strconv.FormatFloat supports several format options.
🌐
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.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-convert-data-types-in-go
How To Convert Data Types in Go | DigitalOcean
May 9, 2019 - You can be sure your float was properly converted to a string because the concatenation was performed without error. 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.
Top answer
1 of 2
29

Both fmt.Sprintf and strconv.FormatFloat use the same string formatting routine under the covers, so should give the same results.

If the precision that the number should be formatted to is variable, then it is probably easier to use FormatFloat, since it avoids the need to construct a format string as you would with Sprintf. If it never changes, then you could use either.

The last argument to FormatFloat controls how values are rounded. From the documentation:

It rounds the result assuming that the original was obtained from a floating-point value of bitSize bits (32 for float32, 64 for float64)

So if you are working with float32 values as in your sample code, then passing 32 is correct.

2 of 2
5

You will have with Go 1.12 (February 2019) and the project cespare/ryu a faster alternative to strconv:

Ryu is a Go implementation of Ryu, a fast algorithm for converting floating-point numbers to strings.
It is a fairly direct Go translation of Ulf Adams's C library.

The strconv.FormatFloat latency is bimodal because of an infrequently-taken slow path that is orders of magnitude more expensive (issue 15672).

The Ryu algorithm requires several lookup tables.
Ulf Adams's C library implements a size optimization (RYU_OPTIMIZE_SIZE) which greatly reduces the size of the float64 tables in exchange for a little more CPU cost.

For a small fraction of inputs, Ryu gives a different value than strconv does for the last digit.
This is due to a bug in strconv: issue 29491.

Go 1.12 might or might not include that new implementation directly in strconv, but if it does not, you can use this project for faster conversion.