Einzelnen Beitrag anzeigen

Benutzerbild von sx2008
sx2008

Registriert seit: 15. Feb 2008
Ort: Baden-Württemberg
2.332 Beiträge
 
Delphi 2007 Professional
 
#7

AW: Truncate float without rounding

  Alt 5. Jan 2014, 19:55
It seems that the Int()-function is rather unknown to most programmers.
Delphi-Quellcode:
Function RoundedReal(n:Double; decimalplaces:Integer):Double;
var multi:Double;
begin
  Assert(decimalplaces >=0);
  multi := IntPower(10, decimalplaces);
  Result := Int(n * multi) / multi;
end;
fork me on Github
  Mit Zitat antworten Zitat