Go 语言类型转换

更新时间: 2019-08-16 09:17

类型转换用于将一种数据类型的变量转换为另外一种类型的变量。Go 语言类型转换基本格式如下:

type_name(expression)

type_name 为类型,expression 为表达式。

实例

以下实例中将整型转化为浮点型,并计算结果,将结果赋值给浮点型变量:

package main

import "fmt"

func main() {
   var sum int = 17
   var count int = 5
   var mean float32

   mean = float32(sum)/float32(count)
   fmt.Printf("mean 的值为: %f\n",mean)
}

以上实例执行输出结果为:

mean 的值为: 3.400000
Google's PageRank and Beyond

Google's PageRank and Beyond

Amy N. Langville、Carl D. Meyer / Princeton University Press / 2006-7-23 / USD 57.50

Why doesn't your home page appear on the first page of search results, even when you query your own name? How do other web pages always appear at the top? What creates these powerful rankings? And how......一起来看看 《Google's PageRank and Beyond》 这本书的介绍吧!

Base64 编码/解码

Base64 编码/解码

Base64 编码/解码

Markdown 在线编辑器

Markdown 在线编辑器

Markdown 在线编辑器

正则表达式在线测试

正则表达式在线测试

正则表达式在线测试