Jump to content

Help With Php Intval Problem


richard_PHP

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.

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.