且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中为最接近的一组数字得到最接近的数字?

更新时间:2023-02-10 22:31:39

这是一个建议。从目标范围中的相应字段中减去测试范围中的每个字段。取每个结果的绝对值并求它们。总赢额最小的范围。可以使用 Math.Abs​​olute(x)找到x的绝对值。更复杂的方法是将绝对值表示为该字段的最大可能值的百分比。

Here is a suggestion. Subtract each field in the test Range from the corresponding field in the target Range. Take the absolute value of each result and sum them. The Range with the smallest total wins. The absolute value of x can be found using Math.Absolute(x) . A more sophisticated method would be to express the absolute value as a percentage of the maximum possible value of that field.