Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Error in funtion Int() a Trunc()

edited January 2012 in General
Hi,
I found error in Int() and Trunc() function. Error is on MS Windows 64bit.

Simple report with Variable, RB 14.02.
Declare:
procedure Variable1OnCalc(var Value: Variant);
var
tmp: Variant; { or Double}
begin
tmp := 187473.11;
Value := Int(1000*tmp);
end;

Windows Vista 32bit: you will see 187473110
Windows 7 64bit: you will see 187473109


Regards
Roman Krupicka

Comments

  • edited January 2012
    Hi Roman,

    This appears to be a Delphi issue when using a double type. You will
    notice that if you place the exact code you have in RAP, into a Delphi
    event handler, you will get the same result.

    As for using variants, this seems to be a limitation of performing a
    calculation inside the parameter of the routine with the numeric value
    first. We will continue to research a solution for this. It looks like
    it has to do with the fact that variants in Delphi do not support the
    Extended type.

    To work around the issue, make the tmp variable type Extended, or place
    a variant only as the parameter of the Int() routine.

    tmp := 187473.11;
    tmp := 1000 * tmp;
    Value := Int(tmp);

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2012
    Hi,
    I did some tests - all on Delphi XE.
    I created simple example:

    In Calculations I created 2 functions:

    function DesatinyStr(Cislo:Extended): string;

    var

    tmp : Extended;

    begin

    tmp := Cislo;

    tmp := 100*Frac(tmp);

    tmp := Round(tmp);

    Result := IntToStr(Abs(tmp));

    end;



    function Abs(const Cislo: Extended):Extended;

    begin

    if Cislo < 0 then

    Result := Cislo * -1

    else

    Result := Cislo;

    end;


    I putted one Variable on detail band and set its calculation:
    var

    tmp: Variant;

    begin

    tmp := 187473.11;

    Value := DesatinyStr(tmp);

    end;



    Windows 7 - 64bit, Delphi XE

    RB 12.05: I see 11

    RB 14.02: I see 10



    Windows Vista - 32bit, Delphi XE
    RB 12.05: I see 11

    RB 14.02: I see 10



    So it looks like some changes between 12 and 14 were made.

    Our reports which worked on RB 12 don't work now in RB 14...



    Thanks

    Roman Krupicka



    --------------------------------------------------------------------------------------

    "Nico Cizik (Digital Metaphors)" píše v diskusním príspevku
  • edited January 2012
    Hi Roman,

    There is now a patch available for RB 14.02 that fixes the issues you
    mention below. Send an email to support@digital-metaphors.com
    requesting the patch and we'll send it to you.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.