Why is the function $ thousand Doesn't work to remove a comma?

I have a serious problem. My page follows a simple formula for updating prices if an item is to be on sale.

<?php if(isset($row_Brand['Sale'])) 
      { 
         $YourPrice = ($row_Brand['Sale'] * number_format($row_Recordset1['Price'], 2, '.', ''));
      } 
      else 
      { 
         ($YourPrice = number_format($row_Recordset1['Price'], 2, '.', '')); 
      } 
  ?>

Cost The price is 1,549.00. However, the number format is 1.00 using the code above. Consequently, the result is gone. This is a serious problem, and I see nothing wrong with the code.

+4
source share
1 answer

The problem is that number_format()it cannot parse the number with a comma in it. You can fix this with str_replace(',', '', $row_Recordset1['Price']), then type number_format()in a number.

if(isset($row_Brand['Sale'])) 
{ 
     $YourPrice = ($row_Brand['Sale'] * number_format(str_replace(',', '', $row_Recordset1['Price']), 2, '.', ''));
} 
else 
{ 
     ($YourPrice = number_format(str_replace(',', '', $row_Recordset1['Price']), 2, '.', '')); 
} 
+3
source

All Articles