Error multiplying decimal integer in php

1

Here is my code example:

$v_quantidade = 10;
$v_preco = '3,68' ;
$v_total   = $v_preco * $v_quantidade;
echo "$v_total"; 

My variable $ v_quantity returns it integers, for example: 3..5..10..20..etc ...

My variable $ v_preco is the price, for example: 3.68.

When I do the above calculation it is returning wrong, this calculation of the example is returning 10.

What am I doing wrong?

And if possible also another question together, some prices may come like this: 3,689 As I present in php only the 3,68

    
asked by anonymous 03.05.2016 / 15:53

1 answer

1

A solution developed with @Diego F and @rray tips

  $v_quantidade = 10;
  $v_preco  = '3,68' ;
  $v_preco  = str_replace(',', '.', $v_preco);
  $v_numero = $v_quantidade * $v_preco; 
  $v_total  = number_format($v_numero, 2, ',', '.');
  echo "<p><b>VALOR TOTAL: R$ $v_total                  </br></p>";
    
03.05.2016 / 16:14