简体   繁体   English

go中的楼层划分

[英]Floor division in go

I'm translating some old come from Python to Go.我正在将一些旧的来自 Python 的内容翻译成 Go。 In this code, I used the floor division with the floor operator in Python.在这段代码中,我在 Python 中使用了 floor 运算符和 floor 运算符。

d = b // c
# (c isn't a comment, I use the // operator from python)

My problem is, this operator doesn't exist in Go.我的问题是,Go 中不存在此运算符。 What's the easiest way to translate in Go?在 Go 中翻译最简单的方法是什么?

If b and c are integers, b / c is already the floor division.如果bc是整数,则b / c已经是底除法了。 If they are float64s, use math.Floor(b/c) .如果它们是 float64s,请使用math.Floor(b/c) If using float32 (or any other numeric type), you must convert first: math.Floor(float64(b)/float64(c))如果使用 float32(或任何其他数字类型),则必须先转换: math.Floor(float64(b)/float64(c))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM