Nikeshh Vijayabaskaran
Nikeshh Vijayabaskaran

Reputation: 223

A non well formed numeric value encountered - Error in PHP

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;

Upvotes: 2

Views: 13665

Answers (2)

PHP Web
PHP Web

Reputation: 257

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;

Upvotes: 1

Nikeshh Vijayabaskaran
Nikeshh Vijayabaskaran

Reputation: 223

I forgot to typecast.

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

Upvotes: 2

Related Questions