-2

I have a variable which value is $79.00 I need to get the 70% of this value which is *0.7 but when I try it returns 0. I have tried str_replace("$", "", $price); but still it doesn't work. any advice?

<?php
$price2          = woocommerce_price($product->min_variation_price); // string(6) "$79.00"
$floated        = (float) str_replace('/&.*?;/', '', $price2);    // float(79)
$seventyPercent = $floated * 0.7;                          // float(55.3)
$reFormatted    = '$' . number_format($seventyPercent, 2); // string(6) "$55.30"
?>
scrowler
  • 24,273
  • 9
  • 60
  • 92
Juan Mrad
  • 23
  • 4

1 Answers1

0

Since you haven't shared the code you're using, it's hard to know why it's not working. As you can see, it's not difficult:

$price          = '$79.00';                                // string(6) "$79.00"
$floated        = (float) str_replace('$', '', $price);    // float(79)
$seventyPercent = $floated * 0.7;                          // float(55.3)
$reFormatted    = '$' . number_format($seventyPercent, 2); // string(6) "$55.30"
scrowler
  • 24,273
  • 9
  • 60
  • 92