デルファイ丸め関数ラウンド、トランク、セル、フロア



Delphi Rounding Function Round



delphi rounding function round, trunc, ceil and floor 1.Round (rounded banker stay double) Function: for a real number is rounded. (Algorithm according to bankers) example: var i, j: Integer begin i: = Round (1.5) // i is equal to 2 j: = Round (2.5) // j is equal to 2 end The answer obtained by using the Round function in Delphi is sometimes not the same with what we expected: the use of a rounded double banker stay. I.e., when the round or more or less than five o'clock position rounded to be processed , And when the round or in place equal to five, it depends on what the previous one, according to odd even enter into, it always returns an even value. example: i: = Round (11.5) // it is equal to 12 i: = Round (10.5) // it is equal to 10 This Round is in fact in accordance with the banker's algorithm, statistically generally use this algorithm to science than the traditional 'rounding.' If you want to use the traditional 'rounding' method, you can use the following functions: function RoundClassic(R: Real) 2.trunc (get the integer part of X) Such as: trunc (-123.55) = - 123, floor (123.55) = 123 3.ceil (to obtain the smallest integer greater than or equal to X) Such as: ceil (-123.55) = - 123, ceil (123.15) = 124 4.floor (to achieve the greatest integer less than or equal to X) Such as: floor (-123.55) = - 124, floor (123.55) = 123 Note: floor and ceil is a math unit in the function, using the former first Uses Math

複製:https://www.cnblogs.com/Myking/archive/2011/07/15/2106956.html