Hi i have another question this time about mathmatical calculations in delphi.

i have 3 labels on the form. Label1 is formatted like this 200/50, i need to use both parts of this caption in the calculation, the calculation needs to be 200 * .50 the 2nd Number in the label is a percentage, so i figure i should just be able to use .50, but in my program i dont want to have to see a . in the middle of the label

Label 2 is formatted like this 00" i would like to know how to ignore the inch character when using floating points.

Label 3 is the value being calculated, which is causing me yet another problem, because the calculation i need to perform is the 2 values in label one multiplied together X 2 then + 25.4 * Label 2 Value, but the total of label 2 needs to be multiplied within the equasion. Like 200 * .50 * 2 + (25.4 * Label2.Caption)

The final result which label 3 displays needs to be to 2 decimal places, i have been using StrToFloat And FloatToString to try this as i think floating points are the best way, but please correct me if im wrong.

thx for the help

PS. Label1 is formatted like XXX/XX i decided against using 2 or 3 labels to do it, because in the 2nd part of the program i need the same Option in a DropDown box, and it will still have to be formatted the same way XXX/XX in the list.

Recommended Answers

All 6 Replies

is the .50 is 0.5 ?
Precedence rule..?
1. ()
2. not
3.*,/,div,mod,and
4.+,-,or,xor
5.<,>,=,<=,>=,<>,=
If there are same of precedence of operators,then the evaluating is left to right...
so
(200*0.5)*2+(25.4*Label2.Caption)

Thanks for the reply,

just managed to cure my calculation problem about 5 mins before you posted, but because label 1 caption is in the format of XXX/XX which is 200/50 i had to use 3 seperate labels to do the job.

and for the 50 i needed to put a . before it, is there anyway i can use 1 Label in the format above and not have to put a . infront of the 2nd part to calculate it.

Because using 3 labels and .50 instead of 50 isnt correct in the software.

one more thing, i need to limit the caption of the label to 2 decimal places.


Label 2 is formatted like this 00" i would like to know how to ignore the inch character when using floating points..

I put 2 labels on the form and a button
Label1.caption is 3.12345
and label2.caption anything,cause the button will evaluate the result of label2.caption....

Procedure TForm1.Button1Click(Sender: TObject);

Var
    after_dot_string:String;
    after_dot_array:Array[1..2]Of Char;
    i:Integer;
Begin

{label1.caption is 3.12345,just example}
after_dot_string:=Label1.Caption;

i:=0;

while (after_dot_string[i]<>'.') Do Begin
  Inc(i);
  If (after_dot_string[i]='.') Then Begin
    after_dot_array[1]:=after_dot_string[i+1];
    after_dot_array[2]:=after_dot_string[i+2];
    Break;
  End;
End;
Label2.Caption:='';
For i:=1 To 2 Do Begin
  Label2.Caption:=Label2.Caption + after_dot_array[i];
End;
 {label2.caption is 12}
End;

Try it,it is works fine..... :D

ok,the array has 3 element of char

Procedure TForm1.Button1Click(Sender: TObject);

Var
    after_dot_string:String;
    after_dot_array:Array[1..3]Of Char; {1..3}
    i:Integer;
Begin

{label1.caption is 3.12345,just example}
after_dot_string:=Label1.Caption;

i:=0;

while (after_dot_string[i]<>'.') Do Begin
  Inc(i);
  If (after_dot_string[i]='.') Then Begin
    after_dot_array[1]:=after_dot_string[i];  {look at this}
    after_dot_array[2]:=after_dot_string[i+1];
    after_dot_array[3]:=after_dot_string[i+2];
    Break;
  End;
End;
Label2.Caption:='';
For i:=1 To 3 Do Begin   {and here 3 steps too}
  Label2.Caption:=Label2.Caption + after_dot_array[i];
End;
 {label2.caption is .12}
End;

Now you can win... :D

Thanks FlamingClaw

solved the stupid problem i was having.
idea worked perfect

Thanks a bunch.

right,then mark as solved,thx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.