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
🌐
Educative
educative.io › answers › how-to-use-the-strconvparsefloat-function-in-golang
How to use the strconv.ParseFloat() function in Golang
Lines 11 to 21: We define the main() function, variable str of string type, and assign a value to it. We pass the variable in the ParseFloat() function, which converts the str variable to a floating-point number with the precision defined by bitSize.
Discussions

strconv.ParseFloat() faster altrernatives
I am parsing huge json files with my own parser where all values are float, which I use in math calculations further on. pprof profiling says 60% of… More on reddit.com
🌐 r/golang
9
2
October 4, 2022
proposal: strconv: add ParseFloatPrefix
The strconv.ParseFloat function parses a floating-point value from a string, but it requires that the floating-point value is the entire string, otherwise it returns an error. In many types of pars... More on github.com
🌐 github.com
10
June 12, 2022
Float parser that sacrifices nothing: refloat
Consider exhaustively testing the 32 bit case. Computers can do it nowadays. 64 is still too much, though be sure to exhaustively test the boundaries. More on reddit.com
🌐 r/golang
9
33
March 9, 2024
🌐
ZetCode
zetcode.com › golang › strconv-parsefloat
Using strconv.ParseFloat in Go
April 20, 2025 - The strconv.ParseFloat function converts a string to a floating-point number.
🌐
Ramesh Fadatare
rameshfadatare.com › home › golang strconv.parsefloat function
Golang strconv.ParseFloat Function
August 11, 2024 - Difference between HashSet and ... strconv.ParseFloat function in Golang is part of the strconv package and is used to parse a string representation of a floating-point number into a float32 or float64 type....
🌐
YourBasic
yourbasic.org › golang › convert-string-to-float
Convert between float and string · YourBasic Go
yourbasic.org/golang · ... 152092096 · 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....
🌐
Cloudhadoop
cloudhadoop.com › home
Golang Example - strconv ParseFloat function guide
December 31, 2023 - package main import ( "fmt" "reflect" "strconv" ) func main() { floatNumb, err: = strconv.ParseFloat("123.23", 32) fmt.Println(floatNumb) fmt.Println(reflect.TypeOf(floatNumb)) fmt.Println(err) float32Value: = float32(floatNumb) // Convert to float 32 fmt.Println(float32Value) fmt.Println(reflect.TypeOf(float32Value)) } Output: 123.2300033569336 float64 <nil> 123.23 float32 · #Golang · #Golang-examples · Categories · Javascript (6) Angular (84) Dart (116) Golang (25) Java (69) Primeng (14) Python (44) Typescript (69) Vuejs (18) Blockchain (1) Reactjs (63) Git (5) Nodejs (64) Node (1) Swift (48) Tags ·
🌐
Go Packages
pkg.go.dev › strconv
strconv package - strconv - Go Packages
ParseFloat accepts decimal and hexadecimal floating-point numbers as defined by the Go syntax for floating-point literals. If s is well-formed and near a valid floating-point number, ParseFloat returns the nearest floating-point number rounded using IEEE754 unbiased rounding.
🌐
TutorialKart
tutorialkart.com › golang-tutorial › golang-convert-string-to-float
How to convert String to Float in Go Language?
July 1, 2021 - package main import ( "fmt" "strconv" ) func main() { var str = "14.2356" result, err := strconv.ParseFloat(str, 32) if err == nil { fmt.Println("The float value is :", result) } else { fmt.Println("There is an error converting string to float.") } }
Find elsewhere
🌐
Reddit
reddit.com › r/golang › strconv.parsefloat() faster altrernatives
r/golang on Reddit: strconv.ParseFloat() faster altrernatives
October 4, 2022 - It seems i'll do that eventually. In the mean time, found ParseFloat from math/big library, but is super slow (~8x wrt strconv.ParseFloat). ... Yeah I imagine it would. ... Thanks for the suggestion. I benchmarked golang port of the simdjson against gjson and gjson was faster for my use case.
🌐
GitHub
gist.github.com › yyscamper › 5657c360fadd6701580f3c0bcca9f63a
An advance ParseFloat for golang, support scientific notation, comma separated number · GitHub
December 13, 2020 - An advance ParseFloat for golang, support scientific notation, comma separated number - parseFloat.go
🌐
Educative
educative.io › answers › how-to-convert-a-string-to-a-float-in-golang
How to convert a string to a float in Golang
A string can be converted to a float in Golang using the ParseFloat function within the strconv package.
🌐
Rez Moss
rezmoss.com › blog › floating-point-parsing-parsefloat-parsecomplex-go-p3-7
Floating Point Parsing - ParseFloat and ParseComplex in Go 3/7 - Rez Moss
September 15, 2025 - The 32-bit version provides approximately 7 decimal digits of precision, while 64-bit offers about 15-17 digits. WWhen bitSize=32, ParseFloat rounds the result to float32 precision; if the value is out of range, it returns ±Inf along with an ErrRange error.
🌐
IncludeHelp
includehelp.com › golang › strconv-parsefloat-function-with-examples.aspx
Golang strconv.ParseFloat() Function with Examples
September 10, 2021 - The return type of the ParseFloat() function is (float64, error), it returns the floating-point number converted from the given string. // Golang program to demonstrate the // example of strconv.ParseFloat() Function package main import ( "fmt" "strconv" ) func main() { fmt.Println(strconv.ParseFloat("123.50", 32)) fmt.Println(strconv.ParseFloat("123.50", 64)) fmt.Println(strconv.ParseFloat("-123456789.501234", 32)) fmt.Println(strconv.ParseFloat("-123456789.501234", 64)) fmt.Println() fmt.Println(strconv.ParseFloat("NaN", 32)) fmt.Println(strconv.ParseFloat("Inf", 32)) fmt.Println(strconv.ParseFloat("-Inf", 32)) }
🌐
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).
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-string-to-float-type-in-golang
How to Convert string to float type in Golang?
May 5, 2023 - The strconv package provides the ParseFloat function to convert a string to a float type. This function takes three arguments - the string to be converted, the bit size of the float type, and the precision of the float type.
🌐
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 - If a1 or a2 is well-formed and near a valid floating-point number, ParseFloat returns the nearest floating-point number rounded using IEEE754 unbiased rounding which is parsing a hexadecimal floating-point value only rounds when there are more bits in the hexadecimal representation than will fit in the mantissa. ... // 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 › 53340
proposal: strconv: add ParseFloatPrefix · Issue #53340 · golang/go
June 12, 2022 - The strconv.ParseFloat function parses a floating-point value from a string, but it requires that the floating-point value is the entire string, otherwise it returns an error. In many types of parsing you want to know if a string starts ...
Author   golang
🌐
Reddit
reddit.com › r/golang › float parser that sacrifices nothing: refloat
r/golang on Reddit: Float parser that sacrifices nothing: refloat
March 9, 2024 -

Hi, I have been working on a library & algorithm to parse floating point numbers. As the standard library has a large lookup table and sort of complicated internally. My approach itself doesn't require any lookup tables, yet it's actually a bit faster on most cases. It is also accurate, passing hundreds of millions of fuzz tests (although it's still far from 32bit, etc) in addition to strconv's tests. I wrote an article on this experiment, in both Japanese and English! The repo is here: https://github.com/sugawarayuuta/refloat I'd love to see comments/contributions from you! Thank you for reading.

🌐
Reintech
reintech.io › term › understanding-the-strconv-parsefloat-function-in-go
Understanding the strconv.ParseFloat() function in Go | 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).
🌐
Go by Example
gobyexample.com › number-parsing
Go by Example: Number Parsing
Parsing numbers from strings is a basic but common task in many programs; here’s how to do it in Go · The built-in package strconv provides the number parsing