richard_PHP Posted November 10, 2012 Share Posted November 10, 2012 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, Quote Link to comment https://forums.phpfreaks.com/topic/270536-help-with-php-intval-problem/ Share on other sites More sharing options...
gizmola Posted November 13, 2012 Share Posted November 13, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270536-help-with-php-intval-problem/#findComment-1391973 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.