2

I am trying to multiply two values in php which gives me the error A non well formed numeric value encountered

Code:

$value = 2.5/100;
$totalvalue = $value * $totalvalue;
echo $totalvalue;

2 Answers2

2

I forgot to typecast.

$value = 2.5/100;
$totalvalue = $value * (float)$totalvalue;
echo $totalvalue;
1

Use the code below :-

$totalvalue = 1.0 ; //Set $totalvalue and typecast to float

$value = 0.0 ;

$value = 2.5/100;

$totalvalue = $value * $totalvalue;

echo "<br>".$totalvalue;
PHP Web
  • 257
  • 3
  • 8