当前位置:网站首页>Go strconv package
Go strconv package
2022-06-09 10:19:00 【General_ zy】
const
const IntSize = intSize
intSize yes int or uint Number of words of type .
func ParseBool
func ParseBool(str string) (value bool, err error)
- Incoming representation
boolString , Such as :1,0,t - return
booltype
func ParseInt
func ParseInt(s string, base int, bitSize int) (i int64, err error)
bin23:=strconv.FormatInt(int64(23),2)
parseInt, err := strconv.ParseInt(bin23, 2, strconv.IntSize)
if err != nil {
return
}
fmt.Println(parseInt)
// 23
Incoming data can be converted to
intStringbase Specifies the base number represented by the string (2 To 36), If base by 0, Will be judged from the string preposition ,"0x" yes 16 Base number ,"0" yes 8 Base number , It is 10 Base number ;
bitSize Of the expected value bit size , Used for upper limit of value , The final return is int64 type ,0、8、16、32、64 Represent the int、int8、int16、int32、int64;
func ParseUint
func ParseUint(s string, base int, bitSize int) (n uint64, err error)
- Pass in a string representing a positive integer
- Others and
ParseIntidentical
func ParseFloat
func ParseFloat(s string, bitSize int) (f float64, err error)
Parses a string representing a floating-point number and returns its value .
func FormatBool
func FormatBool(b bool) string
take bool Value to string
func FormatInt
func FormatInt(i int64, base int) string
fmt.Println(strconv.FormatInt(int64(23),2))
// 10111
- Pass in
int64And a base number - Returns the string after converting the number according to the decimal
func FormatUint
func FormatUint(i uint64, base int) string
- Positive integer
- The rest is the same as above
func FormatFloat
func FormatFloat(f float64, fmt byte, prec, bitSize int) string
fmt.Println(strconv.FormatFloat(float64(32),'f',10,64))
//32.0000000000
Function represents a floating-point number as a string and returns .
fmt Set the format of the return value :‘f’(-ddd.dddd)、‘b’(-ddddp±ddd, The exponent is binary )、‘e’(-d.dddde±dd, Decimal index )、‘E’(-d.ddddE±dd, Decimal index )、‘g’( It's used when the exponent is large ’e’ Format , otherwise ’f’ Format )、‘G’( It's used when the exponent is large ’E’ Format , otherwise ’f’ Format ).
prec Control accuracy ( Exclusion index part ): Yes ’f’、‘e’、‘E’, It represents the number of Numbers behind the decimal point ; Yes ’g’、‘G’, It controls the total number of Numbers . If prec by -1, Is for using the least amount 、 But the necessary Numbers f.
bitSize Express f Source type (32:float32、64:float64), I'm going to round that .
func Atoi
func Atoi(s string) (i int, err error)
Atoi yes ParseInt(s, 10, 0) Abbreviation .
func Itoa
func Itoa(i int) string
Itoa yes FormatInt(i, 10) Abbreviation .
func AppendBoo
func AppendBool(dst []byte, b bool) []byte
tmp:=make([]byte,1,10)
tmp[0]='1'
fmt.Println(strconv.AppendBool(tmp,true))
fmt.Println(string(strconv.AppendBool(tmp,true)))
//[49 116 114 117 101]
//1true
Equivalent to append(dst, FormatBool(b)...) take bool Append to byte slice
func AppendInt
func AppendInt(dst []byte, i int64, base int) []byte
tmp:=make([]byte,1,10)
tmp[0]='1'
fmt.Println(strconv.AppendInt(tmp,23,2))
fmt.Println(string(strconv.AppendInt(tmp,23,2)))
// [49 49 48 49 49 49]
// 110111
Equivalent to append(dst, FormatInt(I, base)...)
func AppendUint
func AppendUint(dst []byte, i uint64, base int) []byte
Equivalent to append(dst, FormatUint(I, base)...)
func AppendFloat
func AppendFloat(dst []byte, f float64, fmt byte, prec int, bitSize int) []byte
Equivalent to append(dst, FormatFloat(f, fmt, prec, bitSize)...)
边栏推荐
- 1108. IP 地址无效化
- Après une perte de 300 millions de dollars, IBM a annoncé sa sortie de Russie!
- 如何实现合规的远程办公?
- Mingdao cloud on the list of office software in China's information and innovation industry in 2022
- 1108. IP address invalidation
- Redis info command memory information description
- 不加班的测试开发工程师不是好程序员?可能不是一只笨鸟,但一直在先飞......
- 构建词表与抽样——【torch学习笔记】
- 剑指 Offer 18. 删除链表的节点
- 面试题 04.02. 最小高度树-深度优先遍历,加树的分治法
猜你喜欢

Security monitoring video easycvr video access interface adds the close button of a single video

Openstack explanation (13) -- Grace keystone setup and startup

机器学习笔记 - 使用scikit-learn创建混淆矩阵
![[genius_platform software platform development] lecture 37: network card hybrid mode and raw socket](/img/bf/880fbf4122b66723b6e17c6d9d97c9.jpg)
[genius_platform software platform development] lecture 37: network card hybrid mode and raw socket

机器学习笔记 - 探索 keras 数据集

8、 Vertices, extremum points and basic feasible solutions of linear programming

AppScan检查到的一些中高危漏洞解决方案

MSF SSH protocol based information collection

WPF 实现带明细的环形图表

机器学习笔记 - 什么是BLEU分数?
随机推荐
UnsupportedOperationException异常解决
[genius_platform software platform development] lecture 37: network card hybrid mode and raw socket
其它权限校验方法
Troubleshooting of soaring memory utilization of redis cluster instances
面试题 10.03. 搜索旋转数组
Terrain learning summary (6) -- terrain practice based on Alibaba cloud platform
机器学习笔记 - R语言学习入门系列一
77.5% of the world's websites are using PHP, the "best language in the world"!
2220. minimum number of bit flips to convert numbers
剑指 Offer II 061. 和最小的 k 个数对-大顶堆法
fabric-ca介紹,安裝,使用
【genius_platform软件平台开发】第三十五讲:UDP进行跨网段广播
Array. Map() shorthand function
MSF tips
Terraform 学习总结(6)—— 基于阿里云平台上的 Terraform 实战
用户目录一站式指南
Blazor University (27)路由 —— 检测导航事件
How to achieve compliant telecommuting?
MSF information collection based on FTP protocol
【LeetCode】【牛客】二叉树刷题