//没有
function ZsTrunc(mFloat: Extended; mTrunc: Integer): Extended; { 指定位数截尾舍入 }
begin
// 987654321.123456789
// +(0)-
mFloat := Int(mFloat * Power(10, -mTrunc));
Result := mFloat * Power(10, mTrunc);
end; { ZsTrunc }function ZsRound(mFloat: Extended; mTrunc: Integer): Extended; { 指定位数四舍五入 }
begin
// 987654321.123456789
// +(0)-
mFloat := Int(mFloat * Power(10, -mTrunc) + 0.5);
Result := mFloat * Power(10, mTrunc);
end; { ZsRound }//Test
procedure TForm1.Button1Click(Sender: TObject);
var
X: Extended;
begin
X := StrToFloat(Edit1.Text);
Caption := Format('%f', [X - ZsTrunc(X, 2)]);
end;
function ZsTrunc(mFloat: Extended; mTrunc: Integer): Extended; { 指定位数截尾舍入 }
begin
// 987654321.123456789
// +(0)-
mFloat := Int(mFloat * Power(10, -mTrunc));
Result := mFloat * Power(10, mTrunc);
end; { ZsTrunc }function ZsRound(mFloat: Extended; mTrunc: Integer): Extended; { 指定位数四舍五入 }
begin
// 987654321.123456789
// +(0)-
mFloat := Int(mFloat * Power(10, -mTrunc) + 0.5);
Result := mFloat * Power(10, mTrunc);
end; { ZsRound }//Test
procedure TForm1.Button1Click(Sender: TObject);
var
X: Extended;
begin
X := StrToFloat(Edit1.Text);
Caption := Format('%f', [X - ZsTrunc(X, 2)]);
end;
//哦别忘了uses Math;
1.如果在系统中,那么可以用Format()函数,然后再StrToFloat()
2.如果是在SQL语句中,那么不同的数据库不太一样,不过一般是ROUND()函数,例如:SQL-SERVER、VFP等
任你在字符串和浮点数之间转换。
Label1.Caption := Format('%.2f',[1234.5678]);
Format('%.2n',[1234.5678]) 可实现1,234.57这样的效果!
D:Double;
begin
D := Trunc(D*100) / 100;
endTrunc is a standard routine,you can get it from Delphi Help.
Good Luck!
OR
formatfloat('0.00',数值);