Jump to content

Recommended Posts

Hello all,

 

I've recently made a post about intval, which was solved. However, the result now has the original values echoed out as well as the resulting shorter integers, which I don't want (see picture).

 

http://imageshack.us/photo/my-images/405/problemsh.jpg

 

Code here, not all code, but the one in question and all surrounding tags:

 

' <td class="dataTableContent" align="right" valign="top">' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . '</td>' . "\n" .
$num = $order->products[$i]["qty"];
if(intval($num) == $num){
$num = intval($num);
}
echo '<td class="dataTableContent" valign="top" align="right">'.$num.'</td>' . "\n" .
' <td class="dataTableContent" align="right" valign="top">' . $currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . '</td>' . "\n";

 

Cheers,

Link to comment
https://forums.phpfreaks.com/topic/270536-help-with-php-intval-problem/
Share on other sites

I have to admit, this gave me a bit of a chuckle:

 

if(intval($num) == $num){
$num = intval($num);
}

 

Let's see... so if intval($num) already == $num, let's go ahead and set it = to what it was already equal to? There's some code that will never execute. ;)

 

I'm picky about this, but typecasting to an int (when you need to) is much faster than calling the intval function. Of course intval does more than casting to an int does, but in most cases you can use a cast to int and achieve the same goal. For example:

 

$num = (int)$num;

 

I'm guessing you probably figured out that we didn't get the posted image, but perhaps that's a security issue on our end? Ok I looked at the link. Image shack is basically a website that stores images and lets you view them in a web page... it's not actually an image that you can reference in an image tag. I editted your post to be a link instead.

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.