四舍五入SimpleRoundTo 与 RoundTo
System.Math
function RoundTo(const AValue: Extended;const ADigit: TRoundToEXRangeExtended): Extended;
function SimpleRoundTo(const AValue: Single; const ADigit: TRoundToRange = -2): Single; overload;
function SimpleRoundTo(const AValue: Double; const ADigit: TRoundToRange = -2): Double; overload;
function SimpleRoundTo(const AValue: Extended; const ADigit: TRoundToRange = -2): Extended; overload;
SimpleRoundTo采用了正负数不对称的算法,当一个负数正好是进位的一半时,它向较大的数进位
实例
var
x,y: Real;
begin
x := 456.125;
y := -456.125;
伪代码
RoundTo(x,-2)=456.12;
RoundTo(y,-2)=-456.13;
//SimpleRoundTo--我们常规需要得四舍五入
SimpleRoundTo(x,-2)=456.13;
SimpleRoundTo(y,-2)=-456.11;
function RoundTo(const AValue: Extended;const ADigit: TRoundToEXRangeExtended): Extended;
function SimpleRoundTo(const AValue: Single; const ADigit: TRoundToRange = -2): Single; overload;
function SimpleRoundTo(const AValue: Double; const ADigit: TRoundToRange = -2): Double; overload;
function SimpleRoundTo(const AValue: Extended; const ADigit: TRoundToRange = -2): Extended; overload;
SimpleRoundTo采用了正负数不对称的算法,当一个负数正好是进位的一半时,它向较大的数进位
实例
var
begin
伪代码