aeroswat Posted June 2, 2010 Share Posted June 2, 2010 Here's my code. For some reason it formats any number that is 1000 or over as 1.00 $val = 1018; if(is_numeric($val)) { $val = number_format($val,2); mysql_query("UPDATE " . ($_SESSION['SESS_DB_YEAR'] == 0 ? 'tblOrders' : 'tblOldOrders' . $_SESSION['SESS_DB_YEAR']) . " SET Cost='" . $val . "' WHERE OrderNumber='" . $order . "'"); echo '1'; $_SESSION['MultiOrderRes'][$pos]['Cost'] = $val; } else{ echo '0'; } All I want for it to do is format all numbers with 2 decimal places. Can anyone illuminate why its doing this? EDIT: Also the field its storing in the database is decimal(10,2) Link to comment https://forums.phpfreaks.com/topic/203681-question-about-number-formatting/ Share on other sites More sharing options...
pornophobic Posted June 2, 2010 Share Posted June 2, 2010 You could try money_format() Link to comment https://forums.phpfreaks.com/topic/203681-question-about-number-formatting/#findComment-1066845 Share on other sites More sharing options...
aeroswat Posted June 2, 2010 Author Share Posted June 2, 2010 I think I figured it out. Possibly cause the SQL field is decimal and its throwing in that thousands seperator ",". I went ahead and added the other two fields number_format($val,2,'.',''); Link to comment https://forums.phpfreaks.com/topic/203681-question-about-number-formatting/#findComment-1066847 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.