当前位置:网站首页>golang 基础 —— 字符串 与 int 、int64 互转
golang 基础 —— 字符串 与 int 、int64 互转
2022-06-30 12:24:00 【猎人在吃肉】
请看代码
package main
import (
"fmt"
"reflect"
"strconv"
)
func main() {
var testStr string = "123456"
// 字符串 转 int
intNum, _ := strconv.Atoi(testStr)
fmt.Println("intNum =", intNum, ", intNum 类型是", reflect.TypeOf(intNum))
// 字符串 转 int64
int64Num, _ := strconv.ParseInt(testStr, 10, 64)
fmt.Println("int64Num=", int64Num, ", int64Num 类型是", reflect.TypeOf(int64Num))
// ===================================================
// int 转 字符串
var intNum2 int = 123456
var str1 string = strconv.Itoa(intNum2)
fmt.Println("str1 =", str1, ", str1 类型是", reflect.TypeOf(str1))
// int64 转 字符串
var int64Num2 int64 = 123456
var str2 string = strconv.FormatInt(int64Num2, 10)
fmt.Println("str2 =", str2, ", str2 类型是", reflect.TypeOf(str2))
}
运行结果:
intNum = 123456 , intNum 类型是 int
int64Num= 123456 , int64Num 类型是 int64
str1 = 123456 , str1 类型是 string
str2 = 123456 , str2 类型是 string
边栏推荐
- Wechat launched the picture big bang function; Apple's self-developed 5g chip may have failed; Microsoft solves the bug that causes edge to stop responding | geek headlines
- 基于ThinkPHP5封装-tronapi-波场接口-源码无加密-可二开--附接口文档-作者详细指导-2022年6月30日08:45:27
- mqtt-ros模拟发布一个自定义消息类型
- [300+ continuous sharing of selected interview questions from large manufacturers] column on interview questions of big data operation and maintenance (II)
- 独立站即web3.0,国家“十四五“规划要求企业建数字化网站!
- [qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external
- Spatiotemporal prediction 2-gcn_ LSTM
- Commands for redis basic operations
- Unity脚本的基础语法(4)-访问其他游戏对象
- MySQL判断执行条件为NULL时,返回0,出错问题解决 Incorrect parameter count in the call to native function ‘ISNULL‘,
猜你喜欢
黑马笔记---集合(Collection的常用方法与遍历方式)
[one day learning awk] use of built-in variables
【MySQL】MySQL的安装与配置
【一天学awk】正则匹配
[qnx hypervisor 2.2 user manual]6.2.3 communication between guest and external
Sarsa notes
【一天学awk】基础中的基础
QT implementation dynamic navigation bar
你想要的异常知识点都在这里了
New function of SuperMap iserver11i -- release and use of legend
随机推荐
时空预测2-GCN_LSTM
[one day learning awk] use of built-in variables
Qt中的数据库使用
全面解析免费及收费SSH工具的基本特性和总结
Mysql根据经纬度查询半径多少以内的数据,画个圈圈查数据库
杭州电子商务研究院:官网(网站)是私域的唯一形态
[QNX Hypervisor 2.2用户手册]6.2.3 Guest与外部之间通信
Qt读写Excel--QXlsx工作表显示/隐藏状态设置4
MySQL中变量的定义和变量的赋值使用
Why should offline stores do new retail?
【一天学awk】正则匹配
Wechat launched the picture big bang function; Apple's self-developed 5g chip may have failed; Microsoft solves the bug that causes edge to stop responding | geek headlines
Efficient elliptic curve point addition and multiplication in scrypt
Videos are stored in a folder every 100 frames, and pictures are transferred to videos after processing
Qt中的事件处理
【OpenGL】OpenGL Examples
基于ThinkPHP5封装-tronapi-波场接口-源码无加密-可二开--附接口文档-作者详细指导-2022年6月30日08:45:27
Docker安装Mysql8和sqlyong连接报错2058的解决方法[随笔记录]
[MySQL] MySQL installation and configuration
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年6月29日21:59:34