Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert int to string type in go language

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how go language converts int into string type". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to convert int into string type in go language" can help you solve the problem.

Conversion method: 1, the use of Itoa () function, syntax "strconv.Itoa (num)"; 2, the use of FormatInt () function, int data can be converted to the specified base and returned in the form of a string, syntax "strconv.FormatInt (num,10)".

Both int type and string type in go language belong to basic data types.

Int integer-to-string-using Itoa ()

The Itoa () function is used to convert the int type data to the corresponding string type. The function signature is as follows.

Func Itoa (I int) string

The sample code is as follows:

Package mainimport ("fmt"strconv") func main () {num: = 100str: = strconv.Itoa (num) fmt.Printf ("type:%T value:%#v\ n", str, str)}

The running result is as follows:

Type:string value: "100"

Int integer-to-string-using FormatInt ()

The FormatInt () function is used to convert the integer data to the specified base and return it as a string. The function signature is as follows:

Func FormatInt (I int64, base int) string

Where parameter I must be of type int64, parameter base must be between 2 and 36, and the lowercase letters "a" to "z" will be used in the returned result to indicate numbers greater than 10.

The sample code is as follows:

Package mainimport ("fmt"strconv") func main () {var num int64 = 100str: = strconv.FormatInt (num, 10) fmt.Printf ("type:%T,value:%v\ n", str, str)}

The running result is as follows:

This is the end of type:string,value:100 's introduction to "how the go language converts int to string type". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report