I have made a new attribute called RRP. It has exactly the same settings as the Price attribute. But when I var_dump
the value inside the attribute it is displaying as a string when I need it to be a float so I can calculate a percentage.
This is what I currently have:
$RRP = Mage::helper('core')->formatPrice($product->getrrp_price());
Which formats the price.
Then I use
$rrp_String = $value = preg_replace('/^\D+/u', '', $RRP);
To make it into a string without the £ so I can have an if-statement to check if it is over 0. How could I change this line to convert $RRP into a float instead of a string?
So I want to replace the $rrp_String
line with something that will convert $RRP
into a float as then I can use it in the same if-statement as well as when I'm trying to calculate percentages using the RRP
Edit
I ended up using:
<?php
$RRP = $product->getrrp_price();
$rrp_float = floatval($RRP);
?>
Without $rrp_String = $value = preg_replace('/^\D+/u', '', $RRP);
This seemed to have solved the problem
'1.5'
to float automatically when needed:var_dump('1.5' / 2);
outputsdouble(0.75)