Dem 4-byte-float Wert in C dürfte in Delphi
Single entsprechen. Probiers einfach mal aus.
raziel
//edit: hab grad ein bisschen rumprobiert:
Damit schreib ich den float in die Datei:
Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
| #include <stdio.h>
int main(int argc, char *argv[]) { FILE *fo; float fl = 3.14159265; printf("%d\n", sizeof fl);
fo = fopen( "c:/float.txt" , "wb" ); if (fo != NULL ) { fwrite( &fl, sizeof(fl), 1, fo ); fflush( fo ); fclose( fo ); } else { printf("Error occured opening file!!"); }
return 0; } |
Damit les ichs in Delphi wieder aus:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| procedure TForm1.Button1Click(Sender: TObject); var fi: file of byte; si: Single; begin if not FileExists(Edit1.Text) then exit; AssignFile(fi, Edit1.Text); Reset(fi); BlockRead(fi, si, sizeof(si)); CloseFile(fi);
Label1.Caption := FormatFloat('####.##########', si); end; |
Wie oben zu sehen schreibe ich
3.14159265 rein, Delphi liest aber
3.141592741 aus...
raziel