# calculate table fields

My Table1 has these values:
ID (Autoinc)
ST_POST (string)
POST_DESC (string)
PERCENT (String)  //Displays Percentage number
HOURS (String) // I manually enter number of hours)
To do some calculus in the grid i added 2 more calculated  fields:
CALC1 (Currency,To get this value i use on calculate fields of the Table1):
Table1CALC1.Value := Query2SALLARY.Value / Table2HOURS_MONTH.Value;
It workz ok...
CALC2 (Currency ...)
How can I get CALC2 to give me results of this formula (if PERCENT ='50'   ! !!!):
CALC2 = a * (b * 50/100) ;
Value 'a' is CALC1
Value 'b' is HOURS
Should I make PERCENT and HOURS into integere type fields as they are allways numbers?
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
why don't you write SQL query that will return values already calculated?

ziolko.
0
Senior DeveloperCommented:
If you want to keep it as strings, then you could do something like this :-

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
var
calc1, calc2: double; // storing in temp variables so you can easily work with them
percent_: double;
hours_: integer;
begin
calc1 := Query2SALARY.Value / Table2HOURS_MONTH.Value;
Table1CALC1.Value := calc1;
// now calculate CALC2
// if using strings
percent_ := 0; // default
hours_ := 0; // default
if (not Table1PERCENT.IsNull) then
percent_ := StrToIntDef(Table1PERCENT.AsString, 0); // default to 0 if not set
if (not Table1HOURS.IsNull) then
hours_ := StrToIntDef(Table1HOURS.AsString, 0); // default to 0 if not set
calc2 := calc1 * (hours_ * (percent_/100)) ;
Table1CALC2.Value := calc2;
end;
0

Experts Exchange Solution brought to you by