[fpc-pascal] real to integer
    Vincent Snijders 
    vsnijders at quicknet.nl
       
    Mon May 29 14:54:01 CEST 2006
    
    
  
Thomas Miller schreef:
> I am frustrated by a very simple problem.  I am trying to convert real 
> to integer, using free pascal for mac.  I am an old Think Pascal user 
> who just recently found free pascal and, while thrilled to have a pascal 
> compiler for mac OSX,  I am still a bit lost.  In Think Pascal, I would 
> have just used "round", but this doesn't seem to work.
> 
> x : integer;
> y : real;
> 
> x := round(y);
> 
> gives me an error saying "got "Double" expected "SmallInt"".   This 
> occurs no matter how I define x:  integer, smallint, etc.  In fact, if I 
> set x to real, then the program compiles and works, simply converting 
> decimal values to 0 but not deleting them.
> 
> I suspect I am making some simple error.  Any advice?
I don't know what is going wrong.
I just created a sample app below on windows and that compiles without errors.
Maybe you can try that.
program Project1;
{$mode objfpc}{$H+}
uses
   Classes, SysUtils
   { add your units here };
var
x : integer;
y : real;
begin
   y := pi;
   x := round(y);
end.
    
    
More information about the fpc-pascal
mailing list