zoukankan      html  css  js  c++  java
  • golang强制类型转换

    
    package main
    
    import (
    	"fmt"
    	"github.com/unknwon/com"
            "strconv"
    )
    
    func main() {
    	test1()
    }
    
    func StringToInt(ctx *gin.Context) {
       a := "123"
       b := com.StrTo(a).MustInt() //string 转 int
       b2 := com.StrTo(a).MustInt64() //string 转 int
       fmt.Printf("%T %s
    ", a, a) //string 123
       fmt.Printf("%T %d
    ", b,b) //int 123
       fmt.Printf("%T %d
    ", b2,b2) //int64 123
    
       var c string = "123"
       c2,_:= strconv.ParseInt(c,10,64)  //string 转 int
       fmt.Printf("%T %s
    ", c, c) //string 123
       fmt.Printf("%T %d
    ", c2,c2) //int64 123
    
       d := "33"
       d1 := com.StrTo(d).MustFloat64() //string 转 float64
       fmt.Printf("%T %s
    ", d,d) //string 33
       fmt.Printf("%T %.2f
    ", d1,d1) //float64 33.00
    
       e,_:= com.StrTo(a).Float64() //string 转 float64
       fmt.Printf("%T %.2f
    ", e,e) //float64 123.00
    
       g:=strconv.Itoa(int(50)) //int转string
       fmt.Printf("%T %.2f
    ", g,g) //string 50
    
       f:=strconv.FormatInt(int64(50), 10) //int64转string
       fmt.Printf("%T %.2f
    ", f,f) //string 50
    
    
    
       //res := testSwitch(a)
       //httpext.SuccessExt(c, res)
    }
    
    
  • 相关阅读:
    Informatica_(6)性能调优
    Informatica_(5)高级应用
    Informatica_(4)工作流
    Informatica_(3)组件
    Informatica_(2)第一个例子
    Informatica_(1)安装
    Linux_(4)Shell编程(下)
    Linux_(3)Shell编程(上)
    Linux_(2)基本命令(下)
    B
  • 原文地址:https://www.cnblogs.com/haima/p/11640188.html
Copyright © 2011-2022 走看看