下面的代码给出了 Writeln(Outfile,testreal) 的实数,并带有“.”。即使我在 Windows 系统中定义了“,”,也可以使用小数分隔符。如何使用 Writeln(Outfile,testreal) 将数字写入文本文件?
(FloatToStr 方法给出了应有的结果。)
procedure TForm1.Button1Click(Sender: TObject);
var Outfile:textfile;
testreal:single;
StrDummy : string;
begin
testreal:=1234.1234;
assignfile(Outfile,'test_real.txt');
Rewrite(Outfile);
StrDummy:='Decimal Separator in Windows: '+GetLocaleChar(GetThreadLocale, LOCALE_SDECIMAL, '.')+#13#10+
'Decimal Separator in Delphi: '+DecimalSeparator;
Writeln(Outfile,StrDummy);
Writeln(Outfile,testreal);
Writeln(Outfile,FloatToStr(testreal));
Closefile(Outfile);
end;
给
Decimal Separator in Windows: ,
Decimal Separator in Delphi: ,
1.23412341308594E+0003 //Ps. Why is there a beginning space here?
1234,12341308594