tw21449.pp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. {$mode objfpc}{$H+}
  2. uses
  3. Classes, SysUtils;
  4. type
  5. data_record = record
  6. amountStr:String;
  7. amount:Currency;
  8. end;
  9. const
  10. kColCount = 5;
  11. kFormatString:array[0..kColCount-1]of String = ( '%1.0f', '%1.1f', '%1.2f', '%1.3f', '%1.4f' );
  12. kRowCount = 2;
  13. kTestData:array[0..kRowCount-1] of data_record = (
  14. (amountStr:'209.98'; amount:209.98 ),
  15. (amountStr:'9.94'; amount:9.94 ) );
  16. ExpectedResults: array[0..kRowCount-1,0..kColCount-1] of string =
  17. (('210','210.0','209.98','209.980','209.9800'),
  18. ('10','9.9','9.94','9.940','9.9400'));
  19. procedure test;
  20. var
  21. amount:Currency;
  22. index:Integer;
  23. rowIndex:Integer;
  24. begin
  25. rowIndex := 0;
  26. while( rowIndex < kRowCount )do
  27. begin
  28. val(kTestData[rowIndex].amountStr,amount,index);
  29. if index<>0 then
  30. halt(1);
  31. write(kTestData[rowIndex].amountStr,' -- ',amount:0:4,': ');
  32. index := 0;
  33. while( index < kColCount )do
  34. begin
  35. write(Format( kFormatString[index], [amount] ),',');
  36. if Format( kFormatString[index], [amount] )<>ExpectedResults[rowindex,index] then
  37. halt(2);
  38. Inc( index );
  39. end;
  40. writeln;
  41. Inc( rowIndex );
  42. end;
  43. end;
  44. begin
  45. test;
  46. writeln('ok');
  47. end.