开发者

php double overflow problem

I'm sure this is quite simple but I can't find the answer.

I'm passing a double into a PHP page, and retrieving it with the code:

$timestamp = $_POST['timestamp'];

The number being passed (1291328282) gets changed into -1456872199 by the PHP s开发者_运维问答cript. The code:

$timestamp = (float) $_POST['timestamp'];

has the same result.


There is no difference in PHP. 'float', 'double' or 'real' are the same datatype.

$_POST['timestamp']; if has the value of 1291328282 is not a double, but an int, it looks like a UNIX_TIMESTAMP not to get confused with EPOCH.

Im not sure what you wish to achive but i think you want:

$timestamp = (int)$_POST['timestamp'];

Little extra knowledge:

When converting from float to string trailing zeros will be dropped.

Example (5.3.^)

echo (string)5.00500; // outputs 5.005
echo (string)30.0000; // outputs 30

What you want to do is:

$timestamp = abs((int)$_POST['timestamp']);


How are you handling the data after declaring the variable? Everything submitted through a form is a string. PHP puts the data into $_POST as strings (except for arrays). $timestamp should have the correct value upon declaration because strings are not constrained like an integer is. What you do with $timestamp after declaring it is what's likely causing PHP to clunk out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜