Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.