Which is better

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Cameri
Forum Commoner
Posts: 87
Joined: Tue Apr 12, 2005 4:12 pm
Location: Santo Domingo, Dominican Republic

Post by Cameri »

:wink:
I ran some tests about a few ways that you could convert something into an integer.
Here's the image: http://cameri.dnsalias.com/cameri/typca ... Sround.jpg

round() returns a float, and that's not what we want, but I included it because it truncates the decimal part too.
floor(), well, it does what it should, return the nearest integer below the number.
intval(), is the function that is supposed to convert a scalar value to an integer.
and last but not least, type casting, which does nothing but truncate the number, dropping the decimal part.
:wink:

EDIT: I forgot to mention that the units are in seconds, and each test case was done with 10,000 loops.
I'm running windows XP with some apps running, so I ran the loops until the standard deviation was less than 0.001 seconds.
Post Reply