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
🌐
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.
Discussions

strconv.ParseFloat() faster altrernatives
You seem to know what you're doing in terms of parsing and profiling. Maybe optimize the ParseFloat implementation . You say you're only accepting a fixed format and I assume a fixed precision, and in the parsing process you're presumably already checking the syntax so you only need the conversion part. You can duplicate ParseFloat and cut the duplicate steps and have something more granular to profile and optimize. 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
strconv: no way to ParseFloat / ParseInt from []byte
The strconv package's ParseFloat / ParseInt only take string. To reduce allocations, I need to parse an int from a []byte. I attempted to convert strconv's Parse internals to use []byte ins... More on github.com
🌐 github.com
3
January 20, 2020
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
🌐
Educative
educative.io › answers › how-to-use-the-strconvparsefloat-function-in-golang
How to use the strconv.ParseFloat() function in Golang
The ParseFloat() function is a strconv package inbuilt function that converts strings to a floating-point number with the precision defined by the bitSize. The value of bitSize must be 32 or 64.
🌐
YourBasic
yourbasic.org › golang › convert-string-to-float
Convert between float and string · YourBasic Go
f := "3.14159265" if s, err := strconv.ParseFloat(f, 32); err == nil { fmt.Println(s) // 3.1415927410125732 } if s, err := strconv.ParseFloat(f, 64); err == nil { fmt.Println(s) // 3.14159265 }
🌐
Reddit
reddit.com › r/golang › strconv.parsefloat() faster altrernatives
r/golang on Reddit: strconv.ParseFloat() faster altrernatives
October 4, 2022 -

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 the time is used by the strconv.ParseFloat(). I looked into the code of the ParseFloat() and it's pretty comprehensive, not much clue on my side. Also I checked github and goolged it, but no results suggesting anything else. I believe the strconv.ParseFloat() is probably pretty optimized but nevertheless, I just wonder if anyone has some faster alternative suggestions to the strconv.ParseFloat()? Thanks..

🌐
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.
🌐
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)) }
🌐
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
Find elsewhere
🌐
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).
🌐
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
🌐
Cloudhadoop
cloudhadoop.com › home
Golang Example - strconv ParseFloat function guide
December 31, 2023 - Following are various uses cases of converting a string to floating types In the below code, ParseFloat() function takes a string and convert it to a floating number with given precision of 64.
🌐
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   benhoyt
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-string-to-float-type-in-golang
How to Convert string to float type in Golang?
May 5, 2023 - In Go, we can convert a string to a float type using the strconv package. 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.
🌐
GitHub
github.com › golang › go › issues › 3197
strconv: no way to ParseFloat / ParseInt from []byte · Issue #3197 · golang/go
January 20, 2020 - The strconv package's ParseFloat / ParseInt only take string. To reduce allocations, I need to parse an int from a []byte. I attempted to convert strconv's Parse internals to use []byte ins...
Author   bradfitz
🌐
TutorialKart
tutorialkart.com › golang-tutorial › golang-convert-string-to-float
How to convert String to Float in Go Language?
July 1, 2021 - To convert a String to a Float value in Go programming, use ParseFloat() function of strconv package.
🌐
GitHub
github.com › golang › go › issues › 36657
strconv: inaccurate string to float64 conversion ParseFloat · Issue #36657 · golang/go
January 20, 2020 - strconv.ParseFloat(...) actually returns 1090544144181609278303144771584. 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
🌐
Go Forum
forum.golangbridge.org › getting help
Potential bug in strconv.ParseFloat - Getting Help - Go Forum
October 10, 2022 - While checking an microservice of our, i noticed that it fails to accept strings like these: “0x15e-2”. The service internally uses strconv.ParseFloat, and the string above is taken straight from the go ref (The Go Programming Language Specification - The Go Programming Language).