Question about formula

Status
Not open for further replies.

marioms

Member
Hello peeps,

I have a question about a calc element I have in my fabrik app.

It calculates the final result of a number from different elements (that are also numbers).

PHP:
$num1 = (int) '{j32db_scitech___Word_Count_Result_1}';
$num2 = (float) '{j32db_scitech___Type_raw}';
$num3 = (int) '{j32db_scitech___Word_Count_Result_2}';
$num4 = (float) '{j32db_scitech___Type_2_raw}';
$num5 = (int) '{j32db_scitech___Word_Count_Result_3}';
$num6 = (float) '{j32db_scitech___Type_3_raw}';
$num7 = (int) '{j32db_scitech___Word_Count_Result_4}';
$num8 = (float) '{j32db_scitech___Type_4_raw}';
return ($num1 / 1000) * ($num2 * 742.35) + ($num3 / 1000) * ($num4 * 742.35) + ($num5 / 1000) * ($num6 * 742.35) + ($num7 / 1000) * ($num8 * 742.35);

I have it as an ajax calculation in my form so it shows on the go the result. I have written in the format string (%01.2f ?) so whenever I save the form, it shows me on the list a number with 2 decimals and the euro symbol.

My request here is... when the element gives me the result on the form itself, it shows me xxxx,xxxxx , in other words, it shows me a lot of decimals I am not interested to see, I want it to give me the number only with 2 decimals in the form, so I see it before I save it correctly. What should I add to the formula I wrote before, on the return part, to see the result only wiht 2 decimals?

Thanks!
 
Another better approach is

Use Form Plugin--- On After Process ( After saving the Form run PHP Script)

The PHP Script should contain:--
Connect to Database
Calculation of Elements Columns
$xyz=@round(($abc*100/$total),2);

the "2" will give value upto 2 decimals
 
But this will give me the result after saving the form, I want to see it on the run with 2 decimals, with ajax, I just need to add something to my formula up but I don't know what T.T
 
Use the round() function
http://php.net/round

So your new code would be

PHP:
$num1 = (int) '{j32db_scitech___Word_Count_Result_1}';
$num2 = (float) '{j32db_scitech___Type_raw}';
$num3 = (int) '{j32db_scitech___Word_Count_Result_2}';
$num4 = (float) '{j32db_scitech___Type_2_raw}';
$num5 = (int) '{j32db_scitech___Word_Count_Result_3}';
$num6 = (float) '{j32db_scitech___Type_3_raw}';
$num7 = (int) '{j32db_scitech___Word_Count_Result_4}';
$num8 = (float) '{j32db_scitech___Type_4_raw}';
$result = ($num1 / 1000) * ($num2 * 742.35) + ($num3 / 1000) * ($num4 * 742.35) + ($num5 / 1000) * ($num6 * 742.35) + ($num7 / 1000) * ($num8 * 742.35);
return round($result, 2);
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top