In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to convert a string into a floating point number in go". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Go language method for converting strings to floating-point numbers: using the ParseFloat () function
The ParseFloat () function is used to convert a string representing a floating point number to a float type, signed as follows.
Func ParseFloat (s string, bitSize int) (f float64, err error)
Parameter description:
If s conforms to the grammatical rules, the function returns a floating-point number closest to the value represented by s (rounded using the IEEE754 specification).
BitSize specifies the type of return value. 32 means float32,64 means float64.
The return value err is of type * NumErr. If the syntax is incorrect err.Error=ErrSyntax, if the return value is out of the range of representation, the return value f is ±Inf,err.Error= ErrRange.
The sample code is as follows:
Package mainimport ("fmt"strconv") func main () {str: = "3.1415926" num, err: = strconv.ParseFloat (str, 64) if err! = nil {fmt.Println (err)} else {fmt.Println (num)}}
The running results are as follows:
3.1415926
Description:
The function all has two return values, the first of which is the converted value, and the second is the error message that the conversion failed.
That's all for "how to convert a string to a floating point number in the go language". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.