问题
Need something like intVal() but for bigger numbers, for example: 100001416147426.
Is there a function like this in php? Can't find it.
回答1:
You should use BC Math, it is designed to numbers of any size with PHP.
The BC Math extensions offers several mathematic functions like:
bcaddAdd two arbitrary precision numbersbccomp— Compare two arbitrary precision numbersbcsqrtGet the square root of an arbitrary precision number- ...
On the PHP documentation site there is a small code example by Charles to round a long number!
回答2:
consider
$x = (double) "100001416147426";
var_dump($x);
output:
float(1.0000141614743E+14)
回答3:
coding standard in the past (since C) has been to follow the number with an L/l $x = 100001416147426L;
This cue's the parser to allocate 64 bits in order to read the number out of the script to compile.
But unless you are running the php x64 this will be useless. Other wise you will have to build it out of a big_number component. Once in a x64 environment intval will automatically expand to a long when exceeding a 32-bit int.
来源:https://stackoverflow.com/questions/7310164/how-to-parse-long-value-in-php