Jump to content

Don't Display '.00'


richard_PHP

Recommended Posts

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

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

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

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.