如何在Ruby中将数字提高到1 / n的幂?

问题描述 投票:0回答:1

我只想将数字提高到1 / n的幂。如果我这样做:2 **(1/7),我总是得1,不管n;当分红为1时,这只是偶像。

提前致谢。

ruby pow arithmetic-expressions
1个回答
4
投票

在控制台中运行1/7,看看你得到了什么。

然后尝试1.0 / 7.0,以避免“整数除法”。

© www.soinside.com 2019 - 2024. All rights reserved.