list获取指定元素总和
没有完全匹配时 (When there is no exact match)
蛋糕分裂 (The cake split)
The cheese cake is precut in 12 slices, and you have played with your friends to win the largest share.
芝士蛋糕被预先切成12片,您已经和朋友一起玩,赢得了最大份额。
The method is, of course, to sum all points achieved and then calculate the share for each player. However, that results in decimal values, meaning that the slices should be sub-sliced and we don't want that. Thus, the shares are rounded to full slices.
当然,该方法是对所有获得的积分求和,然后计算每个玩家的份额。 但是,这会产生十进制值,这意味着应该对切片进行切片,我们不希望这样做。 因此,份额将四舍五入。
The second column shows the points achieved. This is the left graph above.
第二列显示了达到的要点。 这是上面的左图 。
Then follows the players' shares of the cake and how many slices that equals.
然后跟随玩家的蛋糕份额和相等的切片数。
The slices are rounded to obtain the requested count of full slices, but these add up to 13. Thus, one slice has to go, but which? There are some options:
切片经过四舍五入以获得请求的完整切片计数,但是这些总数加起来为13。因此,必须经过一个切片,但是哪个? 有一些选项:
- Reduce the largest count of slices by one 将最大切片数减少一
- Delete the slice that has the smallest share 删除份额最小的切片
- Delete a random slice 删除随机切片
The answer is to reduce where the impact will be smallest. We have two players with three slices, but player 5's count has already been rounded down. Reducing player 1's count of slices will still leave him or here two slices.
答案是减少影响最小的地方。 我们有两名球员,三分,但是第五名的人数已经四舍五入。 减少玩家1的分片数仍会留下他或这里的两个分片。
Two players have been rounded up to one slice. Reducing either of these to zero will have a very large impact, 100%, on the share.
两名球员已四舍五入至一。 将其中任何一个减少到零将对份额产生非常大的影响,即100%。
Thus player 1 is the candidate to give up a slice.
因此,玩家1是放弃分片的候选人。
The last column lists the final count of slices, adding up to the twelve available. This is the right graph above.
最后一列列出了切片的最终数量,总共有十二个可用数量。 这是上面的右图 。
Name |
points
| share | slices | requested | rounded |
---|---|---|---|---|---|
Player 1 | 33 | 0.2171 | 2.605 | 3 | 2 |
Player 2 | 9 | 0.0592 | 0.711 | 1 | 1 |
Player 3 | 13 | 0.0855 | 1.026 | 1 | 1 |
Player 4 | 22 | 0.1447 | 1.737 | 2 | 2 |
Player 5 | 41 | 0.2697 | 3.237 | 3 | 3 |
Player 6 | 11 | 0.0724 | 0.868 | 1 | 1 |
Player 7 | 23 | 0.1513 | 1.816 | 2 | 2 |
Total | 12.000 | 13 | 12 |
名称 |
点数
| 分享 | 切片 | 要求的 | 四舍五入 |
---|---|---|---|---|---|
玩家1 | 33 | 0.2171 | 2.605 | 3 | 2 |
玩家2 | 9 | 0.0592 | 0.711 | 1个 | 1个 |
玩家3 | 13 | 0.0855 | 1.026 | 1个 | 1个 |
玩家4 | 22 | 0.1447 | 1.737 | 2 | 2 |
玩家5 | 41 | 0.2697 | 3.237 | 3 | 3 |
玩家6 | 11 | 0.0724 | 0.868 | 1个 | 1个 |
玩家7 | 23 | 0.1513 | 1.816 | 2 | 2 |
总 | 12.000 | 13 | 12 |
In this small example, the result is easy to figure out. But for a larger count of players - or other items like invoice lines or measurements - it will be difficult to figure out the optimum result. You will need a function to carry it out.
在这个小例子中,结果很容易弄清楚。 但是对于更多的玩家-或其他项目(如发票行或度量)-将很难找出最佳结果。 您将需要一个函数来执行它。
小值和大值的混合 (Mix of small and large values)
Let's take another example where the outcome may not be that obvious. Here, four small values are added with one much larger. The sum of the rounded values (1443) differs with 2 from the rounded total (1441).
让我们再举一个例子,结果可能不是那么明显。 在这里,四个小值相加,一个大得多。 四舍五入后的值之和(1443)与四舍五入后的总数(1441)相差2。
But which values should be corrected?
但是,应该更正哪些值?
You may argue, that the largest value(s) should be corrected, as the imposed error will be the smallest relative to the value. But it would be regarded as strange, that (here) the only value that is hardly rounded would be the one to adjust while the other values, that are rounded up or down quite a lot, should remain.
您可能会争辩说,应该纠正最大值,因为所施加的误差相对于该值将是最小的。 但是,被认为很奇怪的是,(这里)几乎没有舍入的唯一值就是要调整的值,而应该舍入或舍入很多其他值。
However, you could just as well argue, that those values with the largest difference in the rounded value should be adjusted. In the table, that is seen in column Difference. That would call for an adjustment of the values 3 and 2, but leaves the question, it not the value of 4 more likely should have been adjusted.
但是,您也可以辩称,应调整四舍五入后的值差异最大的那些值。 在表中,这在“ 差异”列中可见。 那将需要对值3和2进行调整,但问题是,不是应该更应该对值4进行调整。
There is no single right or wrong method to follow, but a good compromise that will work well in most cases is to weigh the difference meaning multiplying the value and the difference.
没有一个单一的对或错方法可以遵循,但是在大多数情况下会很好地起作用的一个很好的折衷方法是权衡差异 ,即将值与差异相乘。
Those values are listed in the next column. Here you'll see, that the large value due to its very small difference results in with a low figure and that the smallest values, 0.6 rounded to 1, also results in a low figure due to the very low input value. The two at the top (highlighted) will then be those to adjust:
这些值在下一列中列出。 在这里,您将看到,由于其很小的差异导致较大的值导致了较低的数字,而最小值0.6(四舍五入为1)也由于较低的输入值而导致了较低的数字。 顶部(突出显示)的两个将进行调整:
ITEM | INPUT | ROUNDED | DIFFERENCE | WEIGHTED DIFFERENCE | RESULT |
---|---|---|---|---|---|
1 | 1432.99999 | 1433 | 0.00001 | 0.0143 | 1433 |
2 | 2.52 | 3 | 0.48 | 1.2096 | 2 |
3 | 1.51 | 2 | 0.49 | 0.7399 | 2 |
4 | 3.55 | 4 | 0.45 | 1.5975 | 3 |
5 | 0.6 | 1 | 0.4 | 0.2400 | 1 |
Total | 1441.17999 | 1443 | 1441 |
项目 | 输入 | 圆角的 | 区别 | 加权差异 | 结果 |
---|---|---|---|---|---|
1个 | 1432.99999 | 1433 | 0.00001 | 0.0143 | 1433 |
2 | 2.52 | 3 | 0.48 | 1.2096 | 2 |
3 | 1.51 | 2 | 0.49 | 0.7399 | 2 |
4 | 3.55 | 4 | 0.45 | 1.5975 | 3 |
5 | 0.6 | 1个 | 0.4 | 0.2400 | 1个 |
总 | 1441.17999 | 1443 | 1441 |
The final values are listed in column Result, and the total is seen to match the rounded total of the input values.
最终值列在“ 结果”列中,并且总计被视为与输入值的四舍五入的总计相匹配。
如果不存在解决方案 (If no solution exists)
In some situations, there may be several identical input values, and the rounded total doesn't match the sum of the rounded values. So which value to adjust, if adjusting all would generate another mismatch?
在某些情况下,可能会有几个相同的输入值,并且四舍五入后的总数与四舍五入后的值之和不匹配。 那么,如果全部调整都会产生另一个失配,该调整哪个值呢?
You could decide for picking an arbitrary item to adjust. But that is no good solution because several calls of the function with identical input values then might generate different result sets. Thus, a simple rule has been set up:
您可以决定选择要调整的任意项目。 但这不是一个好的解决方案,因为多次调用具有相同输入值的函数可能会生成不同的结果集。 因此,建立了一个简单的规则:
If one of several identical values must be adjusted, pick the first.
如果必须调整几个相同值中的一个,请选择第一个。
An example is shown here:
这里显示一个示例:
ITEM | INPUT | ROUNDED | DIFFERENCE | WEIGHTED DIFFERENCE | RESULT |
---|---|---|---|---|---|
1 | 1.6667 | 1.67 | 0.0033 | 0.00550011 | 1.67 |
2 | 34.6667 | 34.67 | 0.0033 | 0.11440011 | 34.66 |
3 | 5.3333 | 5.33 | -0.0033 | 0.01759989 | 5.33 |
4 | 34.6667 | 34.67 | 0.0033 | 0.11440011 | 34.67 |
5 | 5.3333 | 5.33 | -0.0033 | 0.01759989 | 5.33 |
6 | 5.3333 | 5.33 | -0.0033 | 0.01759989 | 5.33 |
7 | 1.6667 | 1.67 | 0.0033 | 0.00550011 | 1.67 |
8 | 34.6667 | 34.67 | 0.0033 | 0.11440011 | 34.67 |
Total | 123.3334 | 123.34 | 123.33 |
项目 | 输入 | 圆角的 | 区别 | 加权差异 | 结果 |
---|---|---|---|---|---|
1个 | 1.6667 | 1.67 | 0.0033 | 0.00550011 | 1.67 |
2 | 34.6667 | 34.67 | 0.0033 | 0.11440011 | 34.66 |
3 | 5.3333 | 5.33 | -0.0033 | 0.01759989 | 5.33 |
4 | 34.6667 | 34.67 | 0.0033 | 0.11440011 | 34.67 |
5 | 5.3333 | 5.33 | -0.0033 | 0.01759989 | 5.33 |
6 | 5.3333 | 5.33 | -0.0033 | 0.01759989 | 5.33 |
7 | 1.6667 | 1.67 | 0.0033 | 0.00550011 | 1.67 |
8 | 34.6667 | 34.67 | 0.0033 | 0.11440011 | 34.67 |
总 | 123.3334 | 123.34 | 123.33 |
Note, that item 2 has been adjusted down by 0.01 for the sum to match the rounded 123.3334.
请注意,项目2已下调0.01,以使总和与舍入后的123.3334相匹配。
使项目匹配 (Make the items match)
A function to do this for us could take as input an array of the items or values to round and return an array with the rounded values.
为我们执行此操作的函数可以将要舍入的项目或值的数组作为输入,并返回具有舍入值的数组。
This basic method would:
此基本方法将:
- Read the values from the array and sum these 从数组中读取值并求和 这些
- Round the sum to obtain the total 四舍五入取总和
- Scale and round the values 缩放并舍入值
- Sum the rounded values 将四舍五入后的值相加
- Adjust the rounded values until the sum of these matches the total 调整四舍五入的值,直到它们的总和与总计
- Return an array with the rounded and corrected values 返回具有四舍五入和更正值的数组
In addition to basic rounding, the function provided here will:
除基本舍入外,此处提供的功能还将:
- Accept positive, negative, zero, and mixed values 接受正,负,零和混合值
- Reverse the values if the sign of the sum doesn't match the sign of the requested total 如果总和的符号与请求的总和的符号不匹配,请反转这些值
- Scale the values to make the sum of these match the requested total ("cake splitting") 缩放值以使这些值的总和与请求的总数相匹配(“蛋糕拆分”)
- Handle very small and very large values 处理非常小的值和非常大的值
That's quite a few steps and conditions to take care of, thus the function can appear a little long-winded, even though the code is extensively commented in-line. So let's briefly walk through the steps.
这需要考虑很多步骤和条件,因此即使代码在行内有大量注释,该函数也会显得有些冗长。 因此,让我们简要地完成这些步骤。
从数组中读取值并求和 这些 (Read the values from the array and sum these)
The first thing to check is if an array is passed. If so, this is looped and the values are summed as Decimal, If values are very large, the function falls back to use Double.
首先要检查的是是否传递了数组。 如果是这样,则将其循环并将值相加为Decimal。如果值很大,则该函数将退回以使用Double。
' Raise error if an array is not passed.
Item = UBound(Values)
' Ignore errors while summing the values.
On Error Resume Next
If Err.Number = 0 Then
' Try to sum the passed values as a Decimal.
Sum = CDec(0)
For Item = LBound(Values) To UBound(Values)
If IsNumeric(Values(Item)) Then
Sum = Sum + CDec(Values(Item))
If Err.Number <> 0 Then
' Values exceed range of Decimal.
' Exit loop and try using Double.
Exit For
End If
End If
Next
End If
If Err.Number <> 0 Then
' Try to sum the passed values as a Double.
Err.Clear
Sum = CDbl(0)
For Item = LBound(Values) To UBound(Values)
If IsNumeric(Values(Item)) Then
Sum = Sum + CDbl(Values(Item))
If Err.Number <> 0 Then
' Values exceed range of Double.
' Exit loop and raise error.
Exit For
End If
End If
Next
End If
' Collect the error number as "On Error Goto 0" will clear it.
ErrorNumber = Err.Number
On Error GoTo 0
If ErrorNumber <> 0 Then
' Extreme values. Give up.
Error.Raise ErrorNumber
End If
Now we have the rounded values and the sum.
现在我们有了取整的值和总和。
四舍五入取总和 (Round the sum to obtain the total)
Next step it to round the requested total so we know what to aim for. Note, that if either the sum of the values or the total is zero, no scaling is possible as it would imply a division by zero. Also, the sign is recorded for later use.
下一步将其舍入到请求的总数,以便我们知道要达到的目标。 请注意,如果值的总和或总和为零,则无法进行缩放,因为这将意味着被零除。 同样,记录该标志以备后用。
You will notice, that function RoundMid is used here. This is a precision rounding function you can study here:
您会注意到,此处使用了RoundMid函数。 这是一个精确的舍入函数,您可以在这里学习:
Rounding values up, down, by 4/5, or to significant figures
' Correct a missing or invalid parameter value for Total.
If Not IsNumeric(Total) Then
Total = 0
End If
If Total = 0 Then
RoundedTotal = 0
Else
' Round Total to an appropriate data type.
' Set data type of RoundedTotal to match Sum.
Select Case VarType(Sum)
Case vbSingle, vbDouble
Value = CDbl(Total)
Case Else
Value = CDec(Total)
End Select
RoundedTotal = RoundMid(Value, NumDigitsAfterDecimal)
End If
' Calculate scaling factor and sign.
If Sum = 0 Or RoundedTotal = 0 Then
' Cannot scale a value of zero.
Sign = 1
Ratio = 1
Else
Sign = Sgn(Sum) * Sgn(RoundedTotal)
' Ignore error and convert to Double if total exceeds the range of Decimal.
On Error Resume Next
Ratio = Abs(RoundedTotal / Sum)
If Err.Number <> 0 Then
RoundedTotal = CDbl(RoundedTotal)
Ratio = Abs(RoundedTotal / Sum)
End If
On Error GoTo 0
End If
Now we have the basic bits and pieces and can start creating the output.
现在我们有了基本的细节,可以开始创建输出了。
缩放并四舍五入值,然后将四舍五入后的值相加 (Scale and round the values and sum the rounded values)
For the output, we create two arrays - one to hold the values and one to hold the sorting of these.
对于输出,我们创建两个数组-一个用于保存值,另一个用于保存这些值的排序。
The first we fill here, later we fill the array for sorting.
我们首先在这里填充,后来我们填充数组进行排序。
' Create array to hold the rounded values.
RoundedValues = Values
' Scale and round the values and sum the rounded values.
' Variables will get the data type of RoundedValues.
' Ignore error and convert to Double if total exceeds the range of Decimal.
On Error Resume Next
For Item = LBound(Values) To UBound(Values)
RoundedValues(Item) = RoundMid(Values(Item) * Ratio, NumDigitsAfterDecimal)
If RoundedValues(Item) > 0 Then
PlusSum = PlusSum + Values(Item)
RoundedPlusSum = RoundedPlusSum + RoundedValues(Item)
If Err.Number <> 0 Then
RoundedPlusSum = CDbl(RoundedPlusSum) + CDbl(RoundedValues(Item))
End If
Else
MinusSum = MinusSum + Values(Item)
RoundedMinusSum = RoundedMinusSum + RoundedValues(Item)
If Err.Number <> 0 Then
RoundedMinusSum = CDbl(RoundedMinusSum) + CDbl(RoundedValues(Item))
End If
End If
Next
RoundedSum = RoundedPlusSum + RoundedMinusSum
If Err.Number <> 0 Then
RoundedPlusSum = CDbl(RoundedPlusSum)
RoundedMinusSum = CDbl(RoundedMinusSum)
RoundedSum = RoundedPlusSum + RoundedMinusSum
End If
On Error GoTo 0
If RoundedTotal = 0 Then
' No total is requested.
' Use as total the rounded sum of the passed unrounded values.
RoundedTotal = RoundMid(Sum, NumDigitsAfterDecimal)
End If
Note, that positive and negative values are summed separately to be able to take care of special cases as seen next.
请注意,正值和负值分别相加,以便能够处理特殊情况,如下所示。
调整四舍五入的值,直到它们的总和与总计 (Adjust the rounded values until the sum of these matches the total)
This is the crucial part where we use the array to hold the sort order of the values.
这是我们使用数组保存值的排序顺序的关键部分。
First a third array, SortingValues, is created and filled with the calculated values to sort on. Note, that the values are made absolute.
首先,创建第三个数组SortingValues,并填充要计算的计算值。 注意,这些值是绝对的。
These two arrays are then sorted by an external function, QuickSortIndex, which is a traditional quick sort function modified to leave the source array untouched and leave the sorting order in the array for the sort order.
然后,通过外部函数QuickSortIndex对这两个数组进行排序,该函数是对传统的快速排序函数进行了修改,以使源数组保持不变,并使排序顺序保持在数组中。
The sorting is used to order the values after the relative error the rounding of these will cause. This may seem cryptic, but those values are used later to determine the order in which values should be corrected up or down to make the sum of the rounded values match the requested total.
排序用于对这些值的取整会引起的相对误差后的值进行排序。 这看起来似乎很神秘,但是稍后将使用这些值来确定应向上或向下校正值的顺序,以使四舍五入后的值之和与请求的总数相匹配。
In case of a mismatch, the difference is calculated and distributed among the values following the sort order found.
在不匹配的情况下,将按照找到的排序顺序计算差异并将其分配到各个值中。
Note, that if a value is corrected and an identical value reversely signed exists, this is corrected as well. This way, if two values were intended to outweigh each other, they will still do so after a correction.
注意,如果一个值被更正并且存在一个相同的带有反向符号的值,那么它也将被更正。 这样,如果两个值要相互抵消,它们在校正后仍会如此。
Just about every step is documented by the in-line comments.
在线注释记录了几乎每个步骤。
' Check if a correction of the rounded values is needed.
If (RoundedPlusSum + RoundedMinusSum = 0) And (RoundedTotal = 0) Then
' All items are rounded to zero. Nothing to do.
' Return zero.
ElseIf RoundedSum = RoundedTotal Then
' Match. Nothing more to do.
ElseIf RoundedSum = Sign * RoundedTotal Then
' Match, except that values shall be reversely signed.
' Will be done later before exit.
Else
' Correction is needed.
' Redim array to hold the sorting of the rounded values.
ReDim SortedItems(LBound(Values) To UBound(Values))
' Fill array with default sorting.
For Item = LBound(SortedItems) To UBound(SortedItems)
SortedItems(Item) = Item
Next
' Create array to hold the values to sort.
SortingValues = RoundedValues
' Fill the array after the relative rounding error and - for items with equal rounding error - the
' size of the value of items.
For Item = LBound(SortedItems) To UBound(SortedItems)
If Values(SortedItems(Item)) = 0 Then
' Zero value.
SortValue = 0
ElseIf RoundedPlusSum + RoundedMinusSum = 0 Then
' Values have been rounded to zero.
' Use original values.
SortValue = Values(SortedItems(Item))
ElseIf VarType(Values(SortedItems(Item))) = vbDouble Then
' Calculate relative rounding error.
' Value is exceeding Decimal. Use Double.
SortValue = (Values(SortedItems(Item)) * Ratio - CDbl(RoundedValues(SortedItems(Item)))) * (Values(SortedItems(Item)) / Sum)
Else
' Calculate relative rounding error using Decimal.
SortValue = (Values(SortedItems(Item)) * Ratio - RoundedValues(SortedItems(Item))) * (Values(SortedItems(Item)) / Sum)
End If
' Sort on the absolute value.
SortingValues(Item) = Abs(SortValue)
Next
' Sort the array after the relative rounding error and - for items with equal rounding error - the
' size of the value of items.
QuickSortIndex SortedItems, SortingValues
' Distribute a difference between the rounded sum and the requested total.
If RoundedPlusSum + RoundedMinusSum = 0 Then
' All rounded values are zero.
' Set Difference to the rounded total.
Difference = RoundedTotal
Else
Difference = Sgn(RoundedSum) * (Abs(RoundedTotal) - Abs(RoundedSum))
End If
' If Difference is positive, some values must be rounded up.
' If Difference is negative, some values must be rounded down.
' Calculate Delta, the value to increment/decrement by.
Delta = Sgn(Difference) * 10 ^ -NumDigitsAfterDecimal
' Loop the rounded values and increment/decrement by Delta until Difference is zero.
For Item = UBound(SortedItems) To LBound(SortedItems) Step -1
' If values should be incremented, ignore values rounded up.
' If values should be decremented, ignore values rounded down.
If Sgn(Difference) = Sgn(Values(SortedItems(Item)) * Ratio - RoundedValues(SortedItems(Item))) Then
' Adjust this item.
RoundedValues(SortedItems(Item)) = RoundedValues(SortedItems(Item)) + Delta
If Item > LBound(SortedItems) Then
' Check if the next item holds the exact reverse value.
If Values(SortedItems(Item)) = -Values(SortedItems(Item - 1)) Then
' Adjust the next item as well to avoid uneven incrementing.
Item = Item - 1
RoundedValues(SortedItems(Item)) = RoundedValues(SortedItems(Item)) - Delta
Difference = Difference + Delta
End If
End If
Difference = Difference - Delta
End If
If Difference = 0 Then
Exit For
End If
Next
End If
That nearly completes the task.
这几乎完成了任务。
返回具有四舍五入和更正值的数组 (Return an array with the rounded and corrected values)
This final step is where the recorded value of Sign is checked and applied. If needed, the resulting array is simply looped, and the values are reversed.
最后一步是检查和应用Sign的记录值。 如果需要,将简单地循环生成的数组,并将值取反。
If Sign = -1 Then
' The values shall be reversely signed.
For Item = LBound(RoundedValues) To UBound(RoundedValues)
RoundedValues(Item) = -RoundedValues(Item)
Next
End If
' Return the rounded total.
Total = RoundedTotal
' Return the array holding the rounded values.
RoundSum = RoundedValues
Finally, the processed array with the resulting values is returned.
最后,返回具有结果值的已处理数组。
Also, the rounded total - declared ByRef - is returned by reference.
同样,四舍五入的总计-声明为ByRef-通过引用返回。
调用函数 (Calling the function)
The function takes three arguments and returns an array:
该函数接受三个参数并返回一个数组:
Public Function RoundSum( _
ByVal Values As Variant, _
Optional ByRef Total As Variant, _
Optional ByVal NumDigitsAfterDecimal As Long) _
As Variant
Of these, Values is the input array, Total is the total value to return, and NumDigitsAfterDecimal determines how the values are rounded. If positive, rounding will be with decimals, if zero rounding will be to integer values, and - if negative - rounding will be to 10, 100, 1000, etc.
其中, Values是输入数组, Total是要返回的总值,而NumDigitsAfterDecimal确定如何舍入值。 如果为正,则四舍五入为小数点;如果为零,则四舍五入为整数值;如果为负数,则四舍五入为10、100、1000等。
If Total is not specified or is zero, the values will be rounded to have a sum that equals the rounded sum of the unrounded values.
如果未指定Total或为零,则将对这些值进行四舍五入以使其总和等于未四舍五入的值的四舍五入之和 。
The usage is quite simple:
用法很简单:
' Create an array for the example input values.
Values = Array(1.66, 1.66, 1.67, -1.7, 1.66)
' Specify the requested total (optional).
RequestedTotal = -11.12
' Specify the rounding, here with one decimal.
NumDigitsAfterDecimal = 1
' This will entail an expected (rounded) total of -11.1.
' Call the function with the parameters and return an array.
Result = RoundSum(Values, Total, NumDigitsAfterDecimal)
' Now, array Result will hold the rounded values, and Total the rounded total.
' If listed, the rounded values and total will be:
'
' Item Result
' 0 -3.7
' 1 -3.7
' 2 -3.8
' 3 3.8
' 4 -3.7
' Total -11.1
Note that the signs are reversed, as we specified a negative total while the sum of the values was positive.
请注意,符号相反,因为我们指定的总数为负,而总和为正。
进一步阅读 (Further reading)
As mentioned above, another article about demanding rounding is online. This covers basic rounding:
如上所述,另一篇有关要求四舍五入的文章在线上发表。 这涵盖了基本的四舍五入:
Rounding values up, down, by 4/5, or to significant figures
An extended discussion can be found on Wikipedia:
扩展讨论可以在Wikipedia上找到:
Rounding of summands preserving the total
下载 (Download)
The current version can always be found at GitHub VBA.Round
当前版本始终可以在GitHub VBA上找到。
The version for this article is here: Rounding 1.2.3.zip This includes a Microsoft Access 2016 project.
本文的版本位于: 四舍五入1.2.3.zip其中包括一个Microsoft Access 2016项目。
I hope you found this article useful. You are encouraged to ask questions, report any bugs or make any other comments about it below.
希望本文对您有所帮助。 鼓励您在下面提出问题,报告任何错误或对此作出任何其他评论。
Note: If you need further "Support" about this topic, please consider using the Ask a Question feature of Experts Exchange. I monitor questions asked and would be pleased to provide any additional support required in questions asked in this manner, along with other EE experts.
注意 :如果您需要有关此主题的更多“支持”,请考虑使用Experts Exchange 的“提问”功能。 我会监督提出的问题,并很高兴与其他电子工程师一起为以这种方式提出的问题提供所需的任何其他支持。
Please do not forget to press the "Thumbs Up" button if you think this article was helpful and valuable for EE members.
如果您认为本文对EE成员有用且有价值,请不要忘记按下“竖起大拇指”按钮。
翻译自: https://www.experts-exchange.com/articles/31683/Round-elements-of-a-sum-to-match-a-total.html
list获取指定元素总和