Round float number with limit

Posted in Mathematics

This example shows, how to round float number, if you want to get result with specified number of numerals after delimiter.

procedure TForm1.Button1Click(Sender: TObject);
var
  Num, Pow: Real;
  Count: Integer;
begin
  Num:=StrToFloat(Edit1.Text);
  Count:=StrToInt(Edit2.Text);
  Pow:=Power(10,Count);
  Num:=Num*Pow;
  Label3.Caption:=FloatToStr(Round(Num)/Pow);
end;