将int类型转换为int32类型的强制转换

huangapple go评论78阅读模式
英文:

Casting conversion of int to int32

问题

我正在从数据库中提取行,并将结果存储在一个切片/数组中。

我需要计算totalRecords和totalPages。

伪代码:
perPage int32 :=(某个数字)
totalRecords := len(array)
totalPages := perPage/totalRecords

我一直得到这个错误。

终端:
invalid operation: perPage / totalRecords (mismatched types int32 and int)

英文:

I am working on pulling in rows from the Db and storing the results in a Slice/Array

I need to calculate the totalRecords & totalPages.

pseudoCode :: 
perPage int32 := ( some number ) 
totalRecords := len(array)
totalPages := perPage/totalRecords

I keep getting this error.

terminal::
`invalid operation: perPage / totalRecords (mismatched types int32 and int)`

答案1

得分: 2

len(array) 返回一个 int,将其转换为 int32,即 int32(len(array)),或者将 perPage 转换为一个 int

英文:

len(array) returns an int convert it to an int32 int32(len(array)) or convert perPage to an int

huangapple
  • 本文由 发表于 2015年1月20日 04:04:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/28032648.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定