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! Link to comment https://forums.phpfreaks.com/topic/270419-dont-display-00/ 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; } Link to comment https://forums.phpfreaks.com/topic/270419-dont-display-00/#findComment-1390827 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" . Link to comment https://forums.phpfreaks.com/topic/270419-dont-display-00/#findComment-1390842 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? Link to comment https://forums.phpfreaks.com/topic/270419-dont-display-00/#findComment-1390845 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 Link to comment https://forums.phpfreaks.com/topic/270419-dont-display-00/#findComment-1390848 Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 Well that's good Link to comment https://forums.phpfreaks.com/topic/270419-dont-display-00/#findComment-1390860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.