2015-02-04 2 views
4

심각한 문제가 있습니다. 항목이 판매 중이면 내 페이지에서 가격을 업데이트하는 간단한 공식을 수행하고 있습니다.

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

가격의 가치는 1,549.00입니다. 그러나 숫자 형식은 위의 코드를 사용하여 1.00으로 만듭니다. 따라서 결과는 벗어났다. 이것은 심각한 문제이며 코드에 문제가없는 것으로 보입니다.

답변

3

number_format()은 쉼표가있는 숫자를 구문 분석 할 수 없습니다. str_replace(',', '', $row_Recordset1['Price'])으로 문제를 해결 한 다음 number_format() 번호로 해결할 수 있습니다.

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, '.', '')); 
} 
관련 문제