我正在將一些來自 Python 的舊版本翻譯成 Go。在這段代碼中,我使用了 Python 中的 floor 除法和 floor 運(yùn)算符。d = b // c# (c isn't a comment, I use the // operator from python)我的問題是,這個運(yùn)算符在 Go 中不存在。用 Go 翻譯最簡單的方法是什么?
1 回答

白衣染霜花
TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個贊
如果b
和c
是整數(shù),b / c
則已經(jīng)是地板除法。如果它們是 float64,請使用math.Floor(b/c)
. 如果使用 float32(或任何其他數(shù)字類型),則必須先轉(zhuǎn)換:math.Floor(float64(b)/float64(c))
- 1 回答
- 0 關(guān)注
- 108 瀏覽
添加回答
舉報
0/150
提交
取消