USE MATH;
1.系统自带:
roundto();
用法:RoundTo(120.123456, -4) = 120.1235;
2.自定义函数
function FixRoundTo(const AValue: Extended; const ADigit: TRoundToRange): Extended;
var
LFactor: Extended;
begin
LFactor := IntPower(10, ADigit);
if AValue < 0 then
Result := Trunc(AValue / LFactor - 0.5) * LFactor
else
Result := Trunc(AValue / LFactor + 0.500000000001) * LFactor;
end;
用法:FixRoundTo(120.123456, -4) = 120.1235;注意:如果四舍五入的是整数位用正数,反之用负数