Excel rounding function, worksheet function vs VBA

I had an application to return the closest matches to specific values ​​in a large cluster of values ​​(as in the previous question ), and I chose the VBA solution. Although during the use of this application, I noticed that the results for a value of 0.5 are incorrect. I used the VBA Round function, which, it seemed to me, returns 0 for 0.5 rounded values ​​to integers, while the round sheet functions returned 1. Oddly enough, the VBA round function returns 2 for 1.5. I had to replace the worksheet function instead of VBA.

Did I miss something?

+3
source share
3 answers

. VBA Round() Banker, . . :

PRB: VBA 6 Excel

, Microsoft, .

Banker 0,5 , Excel . 0,5 .

+3

( :):

, VBA Round Banker, 0,5 , :

Round (12.55, 1) would return 12.6 (rounds up) 
Round (12.65, 1) would return 12.6 (rounds down) 
Round (12.75, 1) would return 12.8 (rounds up)   

Excel Round, .5 .

, , .5 ( ) , ( ). " ", , , .

SymArith Microsoft VBA , , Fix , , 58.55; , 58,5 58,6. , Round Worksheet Excel, :

Application.Round(58.55, 1)

This will allow you to perform normal rounding in VBA, although it may not be as fast as some custom functions. I understand that this caused a full circle of the question, but I wanted to include it for completeness.

+2
source

Source: https://habr.com/ru/post/1699166/


All Articles