相信delphi7开发人员也遇到过这个问题FormatFloat 四舍五入的时候该进一的时候没进一,测试代码如下:
procedure TForm1.FormShow(Sender: TObject);
var
a:double;
begin
a:=16.685;
showmessage(formatfloat('0.00',a));
application.Terminate;
end;
结果是16.68.
FormatFloat源代码如下
function FormatFloat(const Format: string; Value: Extended): string;
var
Buffer: array[0..255] of Char;
begin
Value:=StrToFloat(FloatToStr(Value));
if Length(Format) > SizeOf(Buffer) - 32 then ConvertError(@SFormatTooLong);
SetString(Result, Buffer, FloatToTextFmt(Buffer, Value, fvExtended,
PChar(Format)));
end;
很明显如果数据类型是extended的话就没问题,即使是这样,我在一个极端的情况下
var
a:Eetended;
begin
a:=clientdataset.fieldbyname('aa').value;
showmessage(formatfloat('0.00',a));
end;
还是出现不进一的情况,最后狠心改了SysUtils.pas.
function FormatFloat(const Format: string; Value: Extended): string;
var
Buffer: array[0..255] of Char;
begin
Value:=StrToFloat(FloatToStr(Value)); //增加了这段代码
if Length(Format) > SizeOf(Buffer) - 32 then ConvertError(@SFormatTooLong);
SetString(Result, Buffer, FloatToTextFmt(Buffer, Value, fvExtended,
PChar(Format)));
end;
问题解决了,最后把SysUtils.dcu共享一下
http://download.youkuaiyun.com/detail/yz304zhang/9852175
把SysUtils.dcu覆盖到Borland\Delphi7\Lib目录下就可以了