Einzelnen Beitrag anzeigen

Andreas13

Registriert seit: 14. Okt 2006
Ort: Nürnberg
711 Beiträge
 
Delphi XE5 Professional
 
#17

AW: System.Frac / System.Int / Math.SimpleRoundTo - komische Ergebnisse

  Alt 12. Jul 2023, 08:08
Versuche mal das obige Beispiel ganz ohne Math.pas mit diesem Code:
Delphi-Quellcode:
function SimpleRoundTo(const AValue: Extended; const ADigit: TRoundToRange = -2): Extended;
var
  LFactor: Extended;
begin
  LFactor := AMath.IntPower(10.0, ADigit);
  if AValue < 0 then
    Result := AMath.Int((AValue / LFactor) - 0.5) * LFactor
  else
    Result := AMath.Int((AValue / LFactor) + 0.5) * LFactor;
end;
Grüße, Andreas
Wenn man seinem Nächsten einen steilen Berg hinaufhilft, kommt man selbst dem Gipfel näher. (John C. Cornelius)
  Mit Zitat antworten Zitat