[Golang系列] go中(int,int64,uint,string,float,bool,interface)类型相互转换
int→string
string := strconv.Itoa(int)
int→int64
int64_ := int64(int)
int64→string
string := strconv.FormatInt(int64,10)
int→float
float := float32(int)
float := float64(int)
int→uint64
uint64 := uint64(int)
float→string
string := strconv.FormatFloat(float64,'E',-1,64)
string := strconv.FormatFloat(float32,'E',-1,32)
参数解释:表示格式:‘f’(ddd.dddd)、‘b’(-ddddp±ddd,指数是二进制)、’e’(-d.dddde±dd,指数是十进制)、’E’(-d.ddddE±dd,指数是十进制)、’g’(指数大时,用’e’格式,否则’f’格式)、’G’(指数大时,用’E’格式,否则’f’格式)
float→int64
int64 := int64(float)
float→int
int := int(float)
string→int
int, err := strconv.Atoi(string)
string→int64
int64, err := strconv.ParseInt(string, 10, 64)
string→float
float,err := strconv.ParseFloat(string,64)
float,err := strconv.ParseFloat(string,32)
string→bool
bool, err := strconv.ParseBool("true")
bool→string
string := strconv.FormatBool(true)
interface→int
interface.(int64)
interface→string
interface.(string)
interface→float
interface.(float64)
interface.(float32)
interface→bool
interface.(bool)
uint64→string
string := strconv.FormatUint(uint64, 10)
相关文章
- [GO]实现定时器指定时间执行
- [Go] 使用protobuf进行序列化和反序列化
- [Linux] nginx记录多种响应时间
- [Go] protobuffer 的环境配置
- [Linux] ubuntu环境安装和使用elasticsearch
- [Linux] 安装grafana并且添加influxdb监控
- [Go] go连接influxdb的库
- [Linux] 获取出日志中的邮箱shell
- [Go] 时序数据库influxdb的安装
- [Go] 在golang中使用正则表达式捕获子表达式
- [Linux] Nginx服务下统计网站的QPS
- [GO项目]开源免费在线客服系统-真正免费开源-GOFLY0.3.5发布-极简强大Go语言开发WEB网页客服
- [Go] go等待读取最后一行的数据内容
- [Linux] 常见的并发模型
- [Go]Golang中控制并发的sync包
- [GO项目]开源免费在线客服系统-真正免费开源-GOFLY0.3.3发布-极简强大Go语言开发网页客服
- [Go] go中的goto语句跳到指定标签
- [Go] golang实时监控日志文件的包tail
- [Go] golang实现mysql连接池
- [Go] 并发imap收信