Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Percentage format... (Math related) Posted by porodoro on 10 Feb 2007 at 6:26 AM
This message was edited by porodoro at 2007-2-10 6:26:20

Hi again,
Im trying to make a program that will calculate the difference of 2 numbers in percentage.

I've made this function:

function MK_PERC(N1,N2):integer;
var S:string;
var S2:integer;
begin
s := Format('%d',[N1-N2]);
s2:=strtoINT(s);
result:=abs(s2);
END;

But it doesnt work.

Any ideas what im doing wrong?



Report
Re: Percentage format... (Math related) Posted by zibadian on 10 Feb 2007 at 6:38 AM
: This message was edited by porodoro at 2007-2-10 6:26:20

: Hi again,
: Im trying to make a program that will calculate the difference of 2 numbers in percentage.
:
: I've made this function:
:
: function MK_PERC(N1,N2):integer;
: var S:string;
: var S2:integer;
: begin
: s := Format('%d',[N1-N2]);
: s2:=strtoINT(s);
: result:=abs(s2);
: END;
:
: But it doesnt work.
:
: Any ideas what im doing wrong?
:
:
First the type of the parameters is missing. Secondly, why so difficult with the conversion from int to string and back again. Your code is the same as this:
function MK_PERC(N1, N2: integer): integer;
begin
  Result := Abs(N1-N2);
end;

which is a lot easier to understand and much faster.
Report
Re: Percentage format... (Math related) Posted by porodoro on 10 Feb 2007 at 12:41 PM
: : This message was edited by porodoro at 2007-2-10 6:26:20

: : Hi again,
: : Im trying to make a program that will calculate the difference of 2 numbers in percentage.
: :
: : I've made this function:
: :
: : function MK_PERC(N1,N2):integer;
: : var S:string;
: : var S2:integer;
: : begin
: : s := Format('%d',[N1-N2]);
: : s2:=strtoINT(s);
: : result:=abs(s2);
: : END;
: :
: : But it doesnt work.
: :
: : Any ideas what im doing wrong?
: :
: :
: First the type of the parameters is missing. Secondly, why so difficult with the conversion from int to string and back again. Your code is the same as this:
:
: function MK_PERC(N1, N2: integer): integer;
: begin
:   Result := Abs(N1-N2);
: end;
: 

: which is a lot easier to understand and much faster.
:
Alright thats better.
I have one more question..

"{$O+}" compiler directive will improve the performance?
And if yes , where should i put it? at the top of each unit?

Report
Re: Percentage format... (Math related) Posted by zibadian on 10 Feb 2007 at 1:46 PM
: : : This message was edited by porodoro at 2007-2-10 6:26:20

: : : Hi again,
: : : Im trying to make a program that will calculate the difference of 2 numbers in percentage.
: : :
: : : I've made this function:
: : :
: : : function MK_PERC(N1,N2):integer;
: : : var S:string;
: : : var S2:integer;
: : : begin
: : : s := Format('%d',[N1-N2]);
: : : s2:=strtoINT(s);
: : : result:=abs(s2);
: : : END;
: : :
: : : But it doesnt work.
: : :
: : : Any ideas what im doing wrong?
: : :
: : :
: : First the type of the parameters is missing. Secondly, why so difficult with the conversion from int to string and back again. Your code is the same as this:
: :
: : function MK_PERC(N1, N2: integer): integer;
: : begin
: :   Result := Abs(N1-N2);
: : end;
: : 

: : which is a lot easier to understand and much faster.
: :
: Alright thats better.
: I have one more question..
:
: "{$O+}" compiler directive will improve the performance?
: And if yes , where should i put it? at the top of each unit?
:
:
It won't improve performance as such, but it will help to make "too large" programs to fit in the memory. For example: TP programs can only use the first 640kB for code, but with overlays you can write programs with up to 2-3 MB of code. The help files clearly state where to place the directive.
Report
Re: Percentage format... (Math related) Posted by porodoro on 11 Feb 2007 at 6:21 AM
: : : : This message was edited by porodoro at 2007-2-10 6:26:20

: : : : Hi again,
: : : : Im trying to make a program that will calculate the difference of 2 numbers in percentage.
: : : :
: : : : I've made this function:
: : : :
: : : : function MK_PERC(N1,N2):integer;
: : : : var S:string;
: : : : var S2:integer;
: : : : begin
: : : : s := Format('%d',[N1-N2]);
: : : : s2:=strtoINT(s);
: : : : result:=abs(s2);
: : : : END;
: : : :
: : : : But it doesnt work.
: : : :
: : : : Any ideas what im doing wrong?
: : : :
: : : :
: : : First the type of the parameters is missing. Secondly, why so difficult with the conversion from int to string and back again. Your code is the same as this:
: : :
: : : function MK_PERC(N1, N2: integer): integer;
: : : begin
: : :   Result := Abs(N1-N2);
: : : end;
: : : 

: : : which is a lot easier to understand and much faster.
: : :
: : Alright thats better.
: : I have one more question..
: :
: : "{$O+}" compiler directive will improve the performance?
: : And if yes , where should i put it? at the top of each unit?
: :
: :
: It won't improve performance as such, but it will help to make "too large" programs to fit in the memory. For example: TP programs can only use the first 640kB for code, but with overlays you can write programs with up to 2-3 MB of code. The help files clearly state where to place the directive.
:
Thanks for the information! .. i got it!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.