在Golang中的数字类型之间进行转换 [英] Casting between number types in golang

查看:65
本文介绍了在Golang中的数字类型之间进行转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我go是否支持数字类型的自动转换。现在,我必须手动将所有计算的结果转换为int或int64,并跟踪所使用的数字类型。

Could someone please tell me if go supports automatic casting of numeric types. Right now I have to manually convert the results of all my computation to int or int64 and keep track of what numeric type I am using.

推荐答案

Go不会自动为您转换数字类型。

Go won't convert numeric types automatically for you.

根据语言规范:


在表达式或赋值
中混合使用不同的数字类型时,需要进行转换。例如,即使int32和int在特定的
体系结构上可能具有相同的大小,它们也不是
相同的类型。

Conversions are required when different numeric types are mixed in an expression or assignment. For instance, int32 and int are not the same type even though they may have the same size on a particular architecture.

这篇关于在Golang中的数字类型之间进行转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆