Registriert seit: 15. Nov 2003
Ort: Berlin
948 Beiträge
Delphi 10.2 Tokyo Professional
|
AW: double in Schleife und Nachkommastellen
11. Dez 2024, 19:40
Für eine Test-Prog habe ich das genutzt:
Code:
...
procedure cnc_Rectangle(XMi, YMi, XMa, YMa: Single; Z : Integer; F : TFormatSettings);
var
X1, X2, Y1, Y2 : Integer;
begin
Memo1.Lines.Add('G1 X' + FormatFloat('0.000',XMi, F) + ' Y' + FormatFloat('0.000',YMi, F));
Memo1.Lines.Add('G1 X' + FormatFloat('0.000',XMa, F) + ' Y' + FormatFloat('0.000',YMi, F));
Memo1.Lines.Add('G1 X' + FormatFloat('0.000',XMa, F) + ' Y' + FormatFloat('0.000',YMa, F));
Memo1.Lines.Add('G1 X' + FormatFloat('0.000',XMi, F) + ' Y' + FormatFloat('0.000',YMa, F));
Memo1.Lines.Add('G1 X' + FormatFloat('0.000',XMi, F) + ' Y' + FormatFloat('0.000',YMi, F));
X1 := Round((XMi * PpMM) * Z);
Y1 := Round((YMi * PpMM) * Z);
X2 := Round((XMa * PpMM) * Z);
Y2 := Round((YMa * PpMM) * Z);
Image1.Picture.Bitmap.Canvas.Rectangle(X1, Y1, X2, Y2);
end;
...
und zurück
Code:
function StrToFloatEx(const S: string; const AFormatSettings: TFormatSettings): Extended;
var
S1, S2 : string;
IsNegativ : Boolean;
Ret : Extended;
begin
IsNegativ := S[1] = '-';
S1 := Copy(S, 1, Pos(AFormatSettings.DecimalSeparator, S) -1);
S2 := '0,' + Copy(S, Pos(AFormatSettings.DecimalSeparator, S) + 1, Length(S));
Ret := StrToInt(S1) + StrToFloat(S2);
if IsNegativ then Result := Ret * -1
else Result := Ret;
end;
|
|
Zitat
|