Problem with Double types
ertankucukoglu opened this issue · 4 comments
Hello,
I am using Delphi 10.3.3, targeting Win32 executable.
I just updated from repository to latest codes available by today. That did not help me. Probably I am missing something obvious here.
Script is generated at runtime. It has some name values which are eventually replaced into their numbers just before script execution. What is entering in compiler is as following
var
xresult,xiskonto,xvadefarki: double;
begin
xvadefarki := (30/ 100) * 1 * 1000;
xiskonto := (0/ 100) * 1 * 1000;
xresult:=(1*1000) + xvadefarki - xiskonto;
Sonuc('Sonuc_Toplam_Tutar',floattostr(xresult));
end.
I get result 1000 for that script which I find is wrong. Because
xvadefarki should be 30
xiskonto should be 0
xresult should be 1300
However, if I use below script (actually only 30 is changed into 30.1)
var
xresult,xiskonto,xvadefarki: double;
begin
xvadefarki := (30.1/ 100) * 1 * 1000;
xiskonto := (0/ 100) * 1 * 1000;
xresult:=(1*1000) + xvadefarki - xiskonto;
Sonuc('Sonuc_Toplam_Tutar',floattostr(xresult));
end.
I get correct result of 1301
I might be missing something obvious here, but I failed to figure it myself.
Any help is appreciated.
Thanks & Regards,
Ertan
By default ROPS performs an integer division if you divide two integers and 30/100 equals 0 in that case.
I've never tested it myself but you can define PS_DELPHIDIV to change this behaviour.
I am not experienced much with PascalScript. Would you advise which unit/file to set that define, please?
Thanks.
It's a compiler directive so you would best set it in your Delphi project settings.
Edit: the term Delphi uses in the settings is 'conditional define'.
Project Options -> Building -> Delphi Compiler -> Conditional defines
I added PS_DELPHIDIV here and it is working as expected.
Thank you.