note 32063 modified in function.intval by et

From: Date: Sat, 03 Jul 2004 09:43:31 +0000
Subject: note 32063 modified in function.intval by et
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72395@lists.php.net to get a copy of this message
Rob_Kohr at no_need_to_email dot me dot com 11-Nov-2002 12:24 [snip] $var=intval("122.5"); //$var==122 This is nice if you want to turn a double into an int automatically rounding down Hum, I had a bug earlier today, involving ===. Coming from a c++ background, I can't help testing for types. I was using floor() to get an integer from a division by 2, and comparing that to a known integer from a for loop. Well, first I changed the === to == because the test would always be false otherwise. Next, I looked up this function, and converted most of my floor() calls to intval() calls, because I really meant to get an int, and not a float with no decimal part. So I have to disagree with the editor note here. Oh, and I'm comfortably back to using ===. --was-- Rob_Kohr at no_need_to_email dot me dot com 11-Nov-2002 12:24 [snip] $var=intval("122.5"); //$var==122 This is nice if you want to turn a double into an int automatically rounding down [editor note: Functions ceil() and floor() should be used to turn floats into integers Maxim] Hum, I had a bug earlier today, involving ===. Coming from a c++ background, I can't help testing for types. I was using floor() to get an integer from a division by 2, and comparing that to a known integer from a for loop. Well, first I changed the === to == because the test would always be false otherwise. Next, I looked up this function, and converted most of my floor() calls to intval() calls, because I really meant to get an int, and not a float with no decimal part. So I have to disagree with the editor note here. Oh, and I'm comfortably back to using ===. http://php.net/manual/en/function.intval.php

« previous php.notes (#72395) next »