我想围绕一个基于两个值的比率的数字。
该比率将包括大于或小于原始值
的值ratio = newValue / originalvalue
当 newValue> originalValue 我可以使用以下方法舍入到最近的较低因子:
double NearestLowerFactor(float value, double factor)
{
return Math.Floor(value / factor) * factor;
}
例如:
当 newValue< originalValue 我希望舍入到该因子的最接近的倒数。
因此,如果因子为2,我想根据1/2的因子进行舍入,即1 / 2,1 / 4,1 / 8,1 / 16等。
例如:
在这种情况下,我如何四舍五入到最接近的较低因子?
答案 0 :(得分:1)
Math.Pow(factor, Math.Floor(Math.Log(ratio, factor)))