Delphi's four rounds

xiaoxiao2021-03-06  39

The answer to the ROUND function in Delphi is sometimes not only the same as what we expect: it is a four-five stay double. That is, when it is more than or less than five hours, according to the round, it is necessary to see what the front is, according to the odd and intake, it always returns an even value. Example Results I: = Round (11.5) 12i: = Round (10.5) 10

This kind of ROUND is actually in accordance with the banker algorithm, and the statistics generally use this algorithm, which is more scientific than traditional "round". If you want to use the traditional "round-stricken" method, you can use the following function:

Function RoundClassic (R: Real): INT64; Begin Result: = Trunc (r); if Frac (r)> = 0.5 Then Result: = Result 1;

In fact, there is this problem in VB, Excel, .NET related languages.

转载请注明原文地址:https://www.9cbs.com/read-74749.html

New Post(0)