The problem is that you try to parse "x.x\n", e.g: 1.8\n. And this returns an error: strconv.ParseFloat: parsing "1.8\n": invalid syntax. You can do a strings.TrimSpace function or to convert feet[:len(feet)-1] to delete \n character

With strings.TrimSpace() (you need to import strings package):

feetFloat, _ := strconv.ParseFloat(strings.TrimSpace(feet), 64)

Wtih feet[:len(feet)-1]:

feetFloat, _ := strconv.ParseFloat(feet[:len(feet)-1], 64)

Output in both cases:

10.8 feet converted to meters give you 3.2918400000000005 meters
Answer from Toni Villena on Stack Overflow
🌐
YourBasic
yourbasic.org › golang › convert-string-to-float
Convert between float and string · YourBasic Go
Use the strconv.ParseFloat function to parse a string as a floating-point number with the precision specified by bitSize: 32 for float32, or 64 for float64.
Discussions

go - How to convert float to string - Stack Overflow
I read a float from a file and will have to convert it to string. My problem here is that I am unsure of how many digits will be there after the decimal. I need to take the float exactly and conver... More on stackoverflow.com
🌐 stackoverflow.com
strconv: inaccurate string to float64 conversion ParseFloat
Here's the code: https://play.golang.org/p/izkaZ-XBog5 · I'm converting string "1090544144181609348835077142190" to float64 with strconv.ParseFloat("1090544144181609348835077142190", 64) and it returns incorrect value. More on github.com
🌐 github.com
20
January 20, 2020
go - How to convert []string to []float64 in Golang? - Stack Overflow
It can't convert because string and int are not compatible. More on stackoverflow.com
🌐 stackoverflow.com
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
🌐
Go Packages
pkg.go.dev › strconv
strconv package - strconv - Go Packages
func ParseFloat(s string, bitSize int) (float64, error) ParseFloat converts the string s to a floating-point number with the precision specified by bitSize: 32 for float32, or 64 for float64.
🌐
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 numeric, then this function will return a float64 value. 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 ...
🌐
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 - The strconv.ParseFloat() function in Go is used to convert a string to a floating-point number. This function takes two arguments: the string to be converted and the number of bits the floating-point number should occupy (32 or 64).
🌐
GeeksforGeeks
geeksforgeeks.org › go language › how-to-convert-string-to-float-type-in-golang
How to Convert string to float type in Golang? - GeeksforGeeks
May 19, 2020 - // Golang program to Convert // string to float type package main import ( "fmt" "strconv" ) func main() { // defining a string a1 a1 := "-2.514" // converting the string a1 // into float and storing it // in b1 using ParseFloat b1, _ := strconv.ParseFloat(a1, 8) // printing the float b1 fmt.Println(b1) a2 := "-2.514" b2, _ := strconv.ParseFloat(a2, 32) fmt.Println(b2) fmt.Println(b1 + b2) } Output:
🌐
GitHub
github.com › golang › go › issues › 36657
strconv: inaccurate string to float64 conversion ParseFloat · Issue #36657 · golang/go
January 20, 2020 - The difference between string value and returned float64 value is 70531932370606 (see https://www.wolframalpha.com/input/?i=1090544144181609348835077142190-1090544144181609278303144771584) Go compiler correctly converts float64 literals to float64 constants, as you can see in Playground example https://play.golang.org/p/izkaZ-XBog5 ·
Author   g7r
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-string-to-float-type-in-golang
How to Convert string to float type in Golang?
May 5, 2023 - This function takes three arguments - the string to be converted, the bit size of the float type, and the precision of the float type. In this article, we will discuss how to convert a string to a float type in Go. The syntax of the ParseFloat function is as follows ? func ParseFloat(s string, ...
🌐
Medium
medium.com › @kode-n-rolla › type-conversion-in-go-a-handy-cheat-sheet-for-developers-51482d4dca0c
Type Conversion in Go: A Handy Cheat Sheet for Developers | by k0de-n-Яolla | Medium
February 27, 2026 - Go’s strings are UTF-8 encoded, so they can include multibyte characters like emojis or non-Latin scripts. Converting to runes ensures accurate handling of characters, especially for indexing or slicing. Go provides built-in support for converting between numeric types like int, float64, and others.
🌐
Educative
educative.io › answers › how-to-use-the-strconvparsefloat-function-in-golang
How to use the strconv.ParseFloat() function in Golang
func ParseFloat(s string, bitSize int) (float64, error) s: This is the string value to parse into the floating-point number. bitSize: This is to specify the precision. The value of bitSize can be 32 or 64. The ParseFloat() function returns the ...
🌐
Go Forum
forum.golangbridge.org › getting help
Problem converting float32 to string - Getting Help - Go Forum
July 20, 2023 - 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,…
🌐
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

🌐
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) }
🌐
Technical Feeder
technicalfeeder.com › 2023 › 03 › golang-how-to-convert-a-value-to-another-data-type
Golang How to convert string to float, int | Technical Feeder
May 23, 2023 - Cast the value with the type. intValue := 128 fmt.Println(float64(intValue)) // 128 fmt.Println(float32(intValue)) // 128 // fmt.Printf format %f has arg intValue of wrong type int fmt.Printf("%f\n", intValue) // %!f(int=128) fmt.Printf("%f\n", ...
🌐
Go
go.dev › src › math › big › floatconv.go
This file implements string-to-Float conversion functions.
The octal prefix "0" is not supported (a leading 249 // "0" is simply considered a "0"). 250 // 251 // A "p" or "P" exponent indicates a base 2 (rather than base 10) exponent; 252 // for instance, "0x1.fffffffffffffp1023" (using base 0) represents the 253 // maximum float64 value. For hexadecimal mantissae, the exponent character 254 // must be one of 'p' or 'P', if present (an "e" or "E" exponent indicator 255 // cannot be distinguished from a mantissa digit). 256 // 257 // The returned *Float f is nil and the value of z is valid but not 258 // defined if an error is reported. 259 func (z *Fl
🌐
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.