richard_PHP Posted November 7, 2012 Share Posted November 7, 2012 Hello all, I have a database which stores values as decimal and then a page which displays the info. I would like when it is a whole number (say 1.00, 2.00, 3.00 etc) to display without the decimals (1, 2, 3 etc) while leaving other numbers as is (1.5, 2.25, 3.08 etc). Cheers in advance! Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 Honestly it will look better and be more visually appealing if you have them all have the same number of decimal places. But if you insist...something like this. $num = 1.00; //$num = 2.5; //$num = 3.051; if(intval($num) == $num){ echo intval($num); }else{ echo $num; } Quote Link to comment Share on other sites More sharing options...
richard_PHP Posted November 7, 2012 Author Share Posted November 7, 2012 Thanks for that. I've looked into putting this into what I have, a downloaded shop system (OSCommerce) and can't find a way to do so. The part where I want the statement to validate is as follows: <td class="dataTableContent" valign="top" align="right">' . $order->products[$i]['qty'] . '</td>' . "\n" . Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 $num = $order->products[$i]['qty']; if(intval($num) == $num){ $num = intval($num); } echo '<td class="dataTableContent" valign="top" align="right">' . $num . '</td>' . "\n" . // etc... In the future, you should probably look at our freelancing board. This is basic code and you didn't know how to use it? Quote Link to comment Share on other sites More sharing options...
richard_PHP Posted November 7, 2012 Author Share Posted November 7, 2012 Unfortunately when I posted the previous message I found how to do it, so simple and I had a lapse.. you beat me to replying!!!! lol. Thanks again Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 Well that's good Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.