Floats and avoid exponential notation - How?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Hi,

 From http://www.php.net/manual/en/language.types.float.php (second comment in that page, from "kjohnson at zootweb dot com"):

"PHP switches from the standard decimal notation to exponential notation for certain "special" floats. You can see a partial list of 
such "special" values with this:"

 Then he goes on about it and finishes with:

 " I have to be honest: this is one of the strangest things I have seen in any language in over 20 years of coding, and it is a 
colossal pain to work around."

 I have the same problem. I have a big number I have to represent, it's usually "1" followed by 10 "zeros", the biggest value I'll 
have for it is 19999999999, never more than this. I only make one operation with it, (+), most of the time I need that number as a 
string, and never need it's float representation, only the absolute value (in fact, it's never going to have a fractional part). I 
cannot use integers because it's bigger than the integer range. 

 If it goes to it's exponential representation, breaks my code. Users are identified by that number. I wrote a small function, but 
cannot be sure if it's going to work (report error when the exponential notation is used by php), mostly because on my tests, I 
can't precise when and to which of these numbers php chooses to use the exponential notation:

--- code
function checkFloat($float_var) {

$ar_empty = "";
$string_var = (string)$float_var;

$pattern = '/[0-9]|\./'; // From zero to nine and "dots"
$match_found = preg_match_all($pattern, $string_var, $ar_empty);

unset($ar_empty);
 if ($match_found != strlen($string_var)) {
        return false;
} else {
        return true;
        }
}
--- code
 
 So, any suggestions/thoughts?
 Is there a way to prevent php from using the exponential notation for a float?


 thanks

=


-- 
Powered by Outblaze

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux