//四舍五入 pValue-传入值 pDigit-小数位数,为不小于0的整数
function FloatDigit(pValue: Double; pDigit: Integer): Double;
var
i: Integer;
nPos,nDigit: Integer;
s,sValue: string;
begin
try
sValue := FloatToStr(pValue);
nPos := Pos('.', sValue);
if nPos <= 0 then
begin
Result := pValue;
end else
begin
nDigit := Length(Copy(sValue, nPos + 1, Length(sValue) - nPos));
if nDigit <= pDigit then
begin
Result := pValue;
end else
begin
if StrToInt(Copy(sValue, nPos + pDigit + 1, 1)) < 5 then
begin
Result := StrToFloat(Copy(sValue, 1, nPos + pDigit));
end else
begin
s := '0.0';
for i := 2 to pDigit + 1 do
s := s + '0';
Result := RoundTo(StrToFloat(Copy(sValue, 1, nPos + pDigit + 1)) + StrToFloat(Copy(s, 1, Length(s) - 1) + '1'), -1 * pDigit);
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载