从string转换为int的数字将改变php中的值 [英] cast a number from string to int would change the value in php

查看:193
本文介绍了从string转换为int的数字将改变php中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP开发项目,并尝试使用 $ _ POST 中的一个参数,不幸的是我想将结果发送到Web服务,它只接受参数为整数。所以我必须使用(int)来转换类型,但是这项工作将改变参数
的值,例如它的类似:

I'm working on a project in PHP, and trying to use one of the parameters in $_POST, unfortunately I want to send the result to a web service, which only accepts the parameter as integer. So I have to cast the type with (int) but this work will change the value of parameter for instance its something like this:

$o =  4924869620;
$c = (int) $o;

然后c的值为629902324

then c will have the value 629902324

为什么会发生这件事?我怎样才能保持价值相同?我还使用了 intval(),它也会改变值

Why this thing happen? how can I keep the value the same?? I have also used intval() and it will also change the value

推荐答案

整数范围从-2.147.483.648开始,到2.147.483.647结束 - 您的数字大于最大范围。使用另一种数据类型,例如float。

Integers range starts at −2.147.483.648 and ends at 2.147.483.647 - your number is bigger than the maximal range. Use another datatype, for example float, instead.

Float的范围从1.5E-45开始并转到3.4E38; o)

Float has a range that starts at 1.5E-45 and goes to 3.4E38 ;o)

这篇关于从string转换为int的数字将改变php中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆