Floats and avoid exponential notation - How?

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

 



 Hi,

 I'm working with floats because I have a big number to identify users, and the only operation I make with this number is to add something less than 10000000000 with 10000000000 (one and ten zeros). Besides that I just need to use the number to search ("=" comparison). I never need the fractional part of the number. As I said, I only use float and not int because of the size of the number.
 I noticed PHP uses the number in exponential notation sometimes, this happened with both: 4100000 + 10000000000 and 4153154 + 10000000000. I'm using ctype_digit() to check when this happens. Is there a way to avoid that so that PHP always uses the decimal notation?

(The focus on my code is not to generate the new user id, I just need to generate it to do other things. Almost all my functions need to generate the new user id, as we cannot map the old user ids to the new user ids. I'm putting two systems together, at least for now, I need to use the old user id from 1 external source and generate the new user id to operate user records on another external db.)

----- code -- (receives "old" user id, and changes to the new format)
$_SESSION['some_array']['old_user_id'] = $userinfo[0]; // I got the number from DB. Say. 4153154..
	$checking_old_user_id = (string)$_SESSION['some_array']['old_user_id']; // So I can use ctype_digit()
	$_SESSION['some_array']['new_user_id'] = (float)10000000000 + $userinfo[0];
	$checking_new_user_id = (string)$_SESSION['some_array']['new_user_id'];
	$_SESSION['some_array']['foo'] = $userinfo[1]; // Other data

	if( ctype_digit($checking_old_user_id) == false ) { // Exponential notation detected
		echo 'some message';
		return false; // Script stops!
	}
	if( ctype_digit($checking_new_user_id) == false ) { // Exponential notation detected
		echo 'some message';
		return false;
	}
	if($_SESSION['some_array']['old_user_id'] < 0) { // Filter input
		echo 'some message';
		return false;
	}
	if($_SESSION['some_array']['new_user_id'] < 0) { // Filter input
		echo 'some message';
		return false;
	}
----- code

 Any ideas, suggestions? I would like to make php stop using the exponential notation so I don't need to bother with these checkings.

 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