Re: Perfect Squares

From: Date: Tue, 25 May 2004 23:32:05 +0000
Subject: Re: Perfect Squares
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-186964@lists.php.net to get a copy of this message
John Kaspar wrote:
Try taking the square root of the variable $sqrt = sqrt($var); then compare the number of decimal places. if (strlen(strstr($sqrt,".")) <= strlen(strstr($var,"."))) {
    // perfect
} Just guessing of course.
I'd do something similar, but a little different: $sqrt = sqrt($var); if ($var == $sqrt * $sqrt) { // perfect }

« previous php.general (#186964) next »