这是一个给定的双
我要根据一定的规则当中,因为我有一定的难度,描述他们,我会通过例子说明,以获得下一个最高数量:
输入所需的输出
------- --------------
0.08 0.1
0.2 0.5
5 10
7 10
99 100
100 500
2345 5000
输出应该在一定意义上的5或10次高的多。
我希望这是可以理解的;如果没有,让我知道。
的实施将是在Java和投入将是积极的双
秒。
函数top5_10(X){
变种10 = Math.pow(10,Math.ceiling(Math.ln(x)的/Math.LN10)));
如果(10→10 * x)的{10 = 10/10; }
否则,如果(十大< = X){10 = 10 * 10; }
返回X< 10/2? 10分/ 2:十;
}
或者是这样的: - )
From a given double
I want to get the next highest number according to some rules which, since I have some difficulty describing them, I will illustrate by examples:
Input Desired output
------- --------------
0.08 0.1
0.2 0.5
5 10
7 10
99 100
100 500
2345 5000
The output should be in some sense the 'next highest multiple of 5 or 10'.
I hope this is understandable; if not, let me know.
The implementation will be in java and input will be positive double
s.
function top5_10 (x) {
var ten = Math.pow(10, Math.ceiling(Math.ln(x)/Math.LN10)));
if (ten > 10 * x) { ten = ten / 10; }
else if (ten <= x) { ten = 10 * ten; }
return x < ten / 2 ? ten / 2 : ten;
}
or something like this :-)