Percentage format... (Math related)

[b][red]This message was edited by porodoro at 2007-2-10 6:26:20[/red][/b][hr]
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?



Comments

  • : [b][red]This message was edited by porodoro at 2007-2-10 6:26:20[/red][/b][hr]
    : 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:
    [code]
    function MK_PERC(N1, N2: integer): integer;
    begin
    Result := Abs(N1-N2);
    end;
    [/code]
    which is a lot easier to understand and much faster.
  • : : [b][red]This message was edited by porodoro at 2007-2-10 6:26:20[/red][/b][hr]
    : : 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:
    : [code]
    : function MK_PERC(N1, N2: integer): integer;
    : begin
    : Result := Abs(N1-N2);
    : end;
    : [/code]
    : 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?

  • : : : [b][red]This message was edited by porodoro at 2007-2-10 6:26:20[/red][/b][hr]
    : : : 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:
    : : [code]
    : : function MK_PERC(N1, N2: integer): integer;
    : : begin
    : : Result := Abs(N1-N2);
    : : end;
    : : [/code]
    : : 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.
  • : : : : [b][red]This message was edited by porodoro at 2007-2-10 6:26:20[/red][/b][hr]
    : : : : 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:
    : : : [code]
    : : : function MK_PERC(N1, N2: integer): integer;
    : : : begin
    : : : Result := Abs(N1-N2);
    : : : end;
    : : : [/code]
    : : : 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!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories