uses StrUtils;procedure TForm1.FormCreate(Sender: TObject); function KeepDigitsAfterDecimalPoint(v: Extended; c: Byte): string; var i: Integer; begin Result := FloatToStr(v); i := Pos('.', Result); if i > 0 then if Length(Result) - i >= c then Result := Copy(Result, 1, i+c) else Result := Result + DupeString('0', c-(Length(Result) - i)) end;begin text:= KeepDigitsAfterDecimalPoint(9.99, 1)end;
更新一下 function KeepDigitsAfterDecimalPoint(v: Extended; c: Byte): string; var i: Integer; begin Result := FloatToStr(v); i := Pos('.', Result); if i = 0 then begin Result := result + '.'; i := Length(Result) end; if c = 0 then Delete(Result, i, Maxint) else if Length(Result) - i >= c then Result := Copy(Result, 1, i+c) else Result := Result + DupeString('0', c-(Length(Result) - i)) end;
function KeepDigitsAfterDecimalPoint(v: Extended; c: Byte): string;
var
i: Integer;
begin
Result := FloatToStr(v);
i := Pos('.', Result);
if i > 0 then
if Length(Result) - i >= c then
Result := Copy(Result, 1, i+c)
else
Result := Result + DupeString('0', c-(Length(Result) - i)) end;begin
text:= KeepDigitsAfterDecimalPoint(9.99, 1)end;
显示FormatFloat,Format,Round...等等这些函数都不能用。
自己转换成字符串截取吧
Edit1.text=‘9.99’;
FloatToStr(Trunc(StrToFloat(edit1.Text)*10)/10);
function KeepDigitsAfterDecimalPoint(v: Extended; c: Byte): string;
var
i: Integer;
begin
Result := FloatToStr(v);
i := Pos('.', Result);
if i = 0 then
begin
Result := result + '.';
i := Length(Result)
end; if c = 0 then
Delete(Result, i, Maxint)
else
if Length(Result) - i >= c then
Result := Copy(Result, 1, i+c)
else
Result := Result + DupeString('0', c-(Length(Result) - i)) end;