inter 是interface类型,转化为string类型是:

str := inter.(string)

转为其他类型也类似

testInt := inter.(int)

testFloat := inter.(float64)

示例如下:

func interface2String(inter interface{}) {switch inter.(type) {case string:fmt.Println("string", inter.(string))breakcase int:fmt.Println("int", inter.(int))breakcase float64:fmt.Println("float64", inter.(float64))break}}func main() {interface2String("jack")interface2String(1)interface2String(12.223)
}

输出结果:

string jack
int 1
float64 12.223

golang interface 转 string,int,float64相关推荐

  1. golang interface 转 int string slice struct 类型

    在golang中,interface{}允许接纳任意值,int, string, struct,slice等,因此我可以很简单的将值传递到interface{} package main import ...

  2. golang string int int32 int64 float32 float64 time 互相转换

    目录 1.float64转int int转int64 2.string和int.int32.int64 3.string和float32.float64 4.string和time 5.转换函数说明 ...

  3. Golang interface 接口详细原理和使用技巧

    文章目录 Golang interface 接口详细原理和使用技巧 一.Go interface 介绍 interface 在 Go 中的重要性说明 interface 的特性 interface 接 ...

  4. go golang 中获取string 长度

    新博客地址(shankusu.me) 以下内容转自自 https://blog.csdn.net/skh2015java/article/details/53258249 一.获取字符串长度的几种方法 ...

  5. The constructor JedisPool(GenericObjectPoolConfig, String, int, int, String) refers to the missing t

    想学习学习redis缓存技术,于是到网上copy到了一些代码,粘贴到ecplise上面,但是发现代码总是报错 The constructor JedisPool(GenericObjectPoolCo ...

  6. java中String,int,Integer,char、double类型转换

    java中String,int,Integer,char.double类型转换----https://www.cnblogs.com/kangyu222/p/5866025.html 转载于:http ...

  7. 如何解决提示the operation % is undefined for the argument type string,int的错误

    今天在做一个用三元运算符判断奇偶的小练习时遇到"the operation % is undefined for the argument type string,int"错误的小 ...

  8. golang []byte 和 string相互转换

    原文链接:golang []byte和string相互转换 测试例子 package mainimport ("fmt" )func main() {str2 := "h ...

  9. String int之间转换

    String int之间转换

最新文章

  1. oracle 截取字段长度substr
  2. Spring5 - 核心原理
  3. Oracle单行函数
  4. vue2.0s中eventBus实现兄弟组件通信
  5. 浙大网新实训项目介绍
  6. HTML小知识点积累
  7. SAP Fiori里的Adapt UI按钮,神出鬼没的奥秘
  8. 有道智能学习灯 初体验
  9. Spring笔记——数据源配置
  10. 数据库笔记11:创建与管理存储过程
  11. 接口测试工具--Apipost不同脚本的作用
  12. 接入微信分享过程的喜和泪
  13. uCOS-II 学习笔记之任务管理--------任务控制块OS_TCB
  14. python爬虫实战万年历
  15. 同时删除多个 Word 文档空白行
  16. 60个英文阅读网站强力推荐
  17. oracle 挖掘日志,使用Oracle的Logminer工具进行日志挖掘
  18. JAVA手机验证码的生成简单实现
  19. 应用程序如何从X86快速换到ARM架构 | 瑞迅科技工控一体机解读
  20. 编程笔试(解析及代码实现):求和为N的正整数序列之实现一个函数,输入为一个正整数N (比如100),输出为所有和等于N的[连续]正整数序列

热门文章

  1. 使用Devstack部署neutron网络节点
  2. mysql将字符串字段转为数字排序或比大小
  3. selenium之 webdriver与三大浏览器版本映射表(更新至v2.29)
  4. 使用atomic一定是线程安全的吗
  5. HeadFirst 设计模式 - Chapte5 单例模式
  6. 今天看到这篇新闻之后,决定休息一下咯
  7. Windows phone应从Android吸取四点教训
  8. 用oracle列实现sqlserver的自增列
  9. 一个常用的表单文本框input输入提示
  10. 工具类静态方法注入dao