自己写函数,然后在事件里调用。这样代码可以重用。 function FormatMoney(ACurrency: Currency): String;
var tempfloat:single; code:integer; begin val(edit1.text,tempfloat,code); if code=0 then edit1.text:=format("#,##0.#0",tempfloat);
着急写成format了,应该是formatfloat var tempfloat:single; code:integer; begin val(edit1.text,tempfloat,code); if code=0 then edit1.text:=formatfloat("#,##0.#0",tempfloat); end;
还要把个位数去掉啊 再改 var tempfloat:single; code:integer; begin val(edit1.text,tempfloat,code); tempfloat:=strtofloat(floattostrf(tempfloat/10,ffFixed,100,0))*10; tempfloat:= if code=0 then edit1.text:=formatfloat("#,##0.#0",tempfloat); end;
这个一般是在DBEDIT1的 change 事件里面写相关转换代码哦
function FormatMoney(ACurrency: Currency): String;
code:integer;
begin
val(edit1.text,tempfloat,code);
if code=0 then
edit1.text:=format("#,##0.#0",tempfloat);
var tempfloat:single;
code:integer;
begin
val(edit1.text,tempfloat,code);
if code=0 then
edit1.text:=formatfloat("#,##0.#0",tempfloat);
end;
再改
var tempfloat:single;
code:integer;
begin
val(edit1.text,tempfloat,code);
tempfloat:=strtofloat(floattostrf(tempfloat/10,ffFixed,100,0))*10;
tempfloat:=
if code=0 then
edit1.text:=formatfloat("#,##0.#0",tempfloat);
end;