Forum Moderators: coopster
Anyway to strip out the - sign? It's stored in the database this way. (It's a number, decimal value 6,2)
<? if ($row->rebateprice < 0.00)
{$row->rebateprice = "($row->rebateprice)";
print "not just free, you make: <font color='#CC0000'>$row->rebateprice</font>"; }
elseif ($row->rebateprice == 0.00)
{$row->rebateprice = "($row->rebateprice)";
print "Free! Your cost: <font color='#CC0000'>$row->rebateprice</font>"; }
elseif ($row->rebateprice > 0.00)
{$row->rebateprice = "$row->rebateprice";
print "Your cost: <font color='#000000'>$row->rebateprice</font>"; }?>
jd
I use a little function like this to ensure that my currency amounts always print out with proper formatting:
function moneyAbs($amount) {
return sprintf('%.2f', abs($amount));
}
In the orginal example, you might do this:
$row->rebateprice = "(" . moneyAbs($row->rebateprice) . ")";
str_replace('-', '', ($row->rebateprice)The main reason formatting in this fashion works is because values for columns of type DECIMAL are typically stored as string values (including the significant decimal place values) and will be returned as such.var_dump($row->rebateprice); // string(6) "-50.00"
Even a simple print() language construct will return the number without significant zeros when it is cast from string to number. And so will var_dump():
print (float) $row->rebateprice; // -50
var_dump(abs($row->rebateprice)); // float(50)