ex90.pp 704 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. Program Example90;
  2. { This program demonstrates the StrToFloat function }
  3. {$mode objfpc}
  4. {$h+ }
  5. Uses SysUtils;
  6. Const
  7. NrValues = 5;
  8. TestStr : Array[1..NrValues] of string =
  9. ('1,1','-0,2','1,2E-4','0','1E4');
  10. Procedure Testit;
  11. Var
  12. I : Integer;
  13. E : Extended;
  14. begin
  15. Writeln('Using DecimalSeparator : ',DecimalSeparator);
  16. For I:=1 to NrValues do
  17. begin
  18. Writeln('Converting : ',TestStr[i]);
  19. Try
  20. E:=StrToFloat(TestStr[i]);
  21. Writeln('Converted value : ',E);
  22. except
  23. On E : Exception do
  24. Writeln('Exception when converting : ',E.Message);
  25. end;
  26. end;
  27. end;
  28. Begin
  29. DecimalSeparator:=',';
  30. Testit;
  31. DecimalSeparator:='.';
  32. Testit;
  33. End.