试试修改一下这个字段的DisplayFormat属性为#0.00%不过,这个字段的值你在写SQL语句的时候得乘以100才行的 例 select a,b,b/a*100 as c from table把字段c的DisplayFormat设为#0.00%
数据库里就不能转换成字符串吗?使用select语句可以直接转换。
在DataSet.AfterOpen里写: DataSet.FieldByName('UrField').OnGetText := MyGetText; 定义过程:procedure MyGetText(Sender: TField; var Text: String; const DisplayText: Boolean);//函数原型可参见TFieldGetEvent帮助 实现: if DisplayText then begin Text := FormatFloat('#,#0.00%', Sender.AsFloat * 100); end else Text := Sender.AsString;
例
select a,b,b/a*100 as c from table把字段c的DisplayFormat设为#0.00%
在DataSet.AfterOpen里写:
DataSet.FieldByName('UrField').OnGetText := MyGetText;
定义过程:procedure MyGetText(Sender: TField; var Text: String; const DisplayText: Boolean);//函数原型可参见TFieldGetEvent帮助
实现:
if DisplayText then
begin
Text := FormatFloat('#,#0.00%', Sender.AsFloat * 100);
end
else
Text := Sender.AsString;