zoukankan      html  css  js  c++  java
  • golang的一些基础数据类型转换

    1. int -- string

      //string到int
      value_int,err:=strconv.Atoi(string)
      //int到string
      str:=strconv.Itoa(value_int)
    2. int64--string

      //string到int64
      value_int64, err := strconv.ParseInt(string, 10, 64)
      //int64到string,需注意下面转换规定
      //FormatInt returns the string representation of i in the given base, for 2 <= base <= 36.
      //The result uses the lower-case letters 'a' to 'z' for digit values >= 10
      str:=strconv.FormatInt(value_int64,10)//FormatInt第二个参数表示进制,10表示十进制。
    3. float--string

      //float转string
      v := 3.1415926535
      s1 := strconv.FormatFloat(v, 'E', -1, 32)//float32s2 := strconv.FormatFloat(v, 'E', -1, 64)//float64
      //第二个参数可选'f'/'e'/'E'等,含义如下:
      // 'b' (-ddddp±ddd,二进制指数)
      // 'e' (-d.dddde±dd,十进制指数)
      // 'E' (-d.ddddE±dd,十进制指数)
      // 'f' (-ddd.dddd,没有指数)
      // 'g' ('e':大指数,'f':其它情况)
      // 'G' ('E':大指数,'f':其它情况)
       
      //string转float
      s := "3.1415926535"
      v1, err := strconv.ParseFloat(v, 32)
      v2, err := strconv.ParseFloat(v, 64)
    4. float--int

      //这个就很简单了
      var a int64
      a = 1
      var b float64
      b = 2.000
       
      //a -- float64
      c := float64(a)
       
      //b -- int64
      d := int64(b)
    还在找我的道
  • 相关阅读:
    DevExpress.XtraCharts.chartControl
    DevExpress控件之:ChartControl 动态绑定数据
    字符串的方法详解
    编码
    格式化输出
    关于while循环中的break和continue的区别
    while循环和for循环
    [AGC028D] Chords
    [CF1392H] ZS Shuffles Cards
    [CF568E] Longest Increasing Subsequence
  • 原文地址:https://www.cnblogs.com/TimLiuDream/p/9897994.html
Copyright © 2011-2022 走看看