calc element and php 7.2

Status
Not open for further replies.

merlino68

Member
I have a field with a simple calculation, but with the passage to php 7.2 a check is made on the fields and it returns the error "A non-numeric value encountered".
how can I change the calculation to avoid this error?

$mycalc= round('{tm_test___peso_sollevato}'/(1.0278-(0.0278*'{tm_test___ripetizioni}')),2);
return $mycalc;


Thanks
 
with (int) around your placeholders work........thanks

in some cases, however, it returns....." Division by zero" do you know how to do a check also for this case?

Thanks
 
Check your placeholder value for not being zero:

E.g like:
$myvar =(int) '{tm_test___ripetizioni}';
if ($myvar != 0) {
//do the calculation
} else {
//do the calculation without $myvar
}
 
Last edited:
unfortunately I don't know the php, I tried this,but i always get the same error:(

$mycalc= round(('{tm_test___Vita}'/'{tm_test___Fianchi}')*100)/100;
$myvar = '{tm_test___Fianchi}';
if ($myvar != 0) {$spoints = $mycalc;}
else
$spoints = "ND";
return $spoints;
 
You have some logic and coding errors in your code. Try something like this:

//convert your value to integer (assuming your placeholder contains integer values, otherwise use float)
$myvar = (int)'{tm_test___Fianchi}';
//test if the placeholder value which is doing the division is not zero
if ($myvar != 0) {
//do the calculation
$mycalc = round((int)'{tm_test___Vita}'/(int)'{tm_test___Fianchi}')*100)/100;
} else {
//value is zero
$mycalc = "ND";
}
return $mycalc;
 
yes, that's perfect .....
a parenthesis was missing and I added it now everything works
Thanks for your help, now I edit all fields with this problem ...

//convert your value to integer (assuming your placeholder contains integer values, otherwise use float)
$myvar = (int)'{tm_test___Fianchi}';
//test if the placeholder value which is doing the division is not zero
if ($myvar != 0) {
//do the calculation
$mycalc = round(((int)'{tm_test___Vita}'/(int)'{tm_test___Fianchi}')*100)/100;
} else {
//value is zero
$mycalc = "ND";
}
return $mycalc;
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top