title: Convert string to decimal php
body: <p>I'm fetching data based on two values​​. The price of a product and the discount on the product. And I want to calculate the difference. The problem is that the values ​​come from the database such as: 22,50 €. I grab this value, I'm removing the "€" and replace "," by "." . But the problem is that when doing subtraction of values​​, the account is not taken.</p>
  
  <p>database comes the variable $discount and $price</p>
  
  <pre><code> $price2 = trim($price,'€'); 
   $price2 = str_replace(",",".",$price2);
   $price2 = floatval($price2);
  
   $discount2 = str_replace(array('€'), '',$discount); 
   $discount2 = str_replace(",",".",$discount2);
   $discount2 = floatval($ver_preco2);
  
  
   $result = ($price2 - $discount2);
  </code></pre>
  
  <p>The variable $discount is not being converted to float and not know why. What is the problem in the variable?</p>