
|
View Full Version : php 18446744073709551615 limit?
shreder 02-25-2007, 05:03 AM Hello.
I have a script where members are maxed out at 18446744073709551615.
Is there any way to solve this?
I have tried to change the field structure in MySQL to decimal,bigint,double but nothing works.
Any help would be appreciated!
Thank you!
stuffradio 02-25-2007, 05:17 AM Umm.... Just make it Int 30? Or something
shreder 02-25-2007, 05:22 AM No, this won't help.
I can even have int 50 and 184467440737095516151234567891010
but it will only show 18446744073709551615
somewhere in the code you are treating that variable as string and cutting it. If you notice it is not even rounded, just cut. Search all operations on the variable and check you are not doing any conversion.
Q
shreder 02-25-2007, 05:38 AM I have these:
function commas ($str){
return number_format(floor($str));
}
could this be the cause?
shreder 02-25-2007, 05:55 AM Ok, i think i found the problem.
It seems that number_format can't handle such big numbers...
How do i use such a big number and seperate it with commas?
Is there any other way except number_format?
Thank you.
bigfan 02-25-2007, 08:56 AM Is there any other way except number_format?Of course there is. PHP wouldn't be much of a language otherwise.$num = chunk_split(strrev($num), 3, ',');
$num = trim(strrev($num), ',');Why are you trying to store this in the db as an integer? Store it as a string, and if you need to do artithmetic with it, use PHP's BCMath (http://php.net/manual/en/ref.bc.php).
shreder 02-25-2007, 09:11 AM How do i store it as a string instead of integer?
bigfan 02-25-2007, 09:21 AM ALTER TABLE my_table CHANGE big_num CHAR (50)
shreder 02-25-2007, 12:14 PM ALTER TABLE my_table CHANGE big_num CHAR (50)
It's not working for some reason, maybe i'm doing something wrong?
What i have is a script, an online game and my players networth reach huge amounts and they are all getting maxed at 18446744073709551615 for some reason.
I tried chancing the sql structure to decimal and double but nothing works.
I have also tried changing it to VARCHAR and then it actually allowed larger numbers in the field itself but when i used number_format it again didn't show the whole number from the field but a shorter number.
I am desperate, seriously... :confused:
Please help me...
bigfan 02-25-2007, 02:57 PM I tried chancing the sql structure to decimal and double but nothing works.Which is why I suggested changing it to a char field....VARCHAR and then it actually allowed larger numbers in the field...Again, as I suggested (two posts ago).
...when i used number_format it again didn't show the whole number from the field but a shorter number.Then why do ypu persist in using number_format()? Do you, for some reason, not want to use the code I gave you (four posts ago)?
shreder 02-25-2007, 06:18 PM I used VARCHAR but then in a ranks table i have when the order should be descending by the "Networth" of a member it's not in the right order.
You could find the member with the highest networth actually ranked 5th and everything is not in the order.
I also tried this:
$num = chunk_split(strrev($num), 3, ',');
$num = trim(strrev($num), ',');
But it seemed to work at first but then i got number like 12,888.8 and 1,678,12 and similar things.
I would even pay someone to fix this for me, just tell me how to fix it as i am losing members...
Thank you!
bigfan 02-26-2007, 09:51 AM ...i got number like 12,888.8 and 1,678,12...For the first--you implied in your first and subsequent posts that you were working with integers. Has that secretly changed?
For the second--if you got 1,678,12 from 167812 with that code, then your computer is broken.
If the rankings are coming out as you say, then there is something wrong with your ordering code.
Burhan 02-27-2007, 02:30 AM 18446744073709551615 is not some random junk. It is the upper limit of an 8 byte unsigned long integer; which also happens to be what the 'bigint' column max is in MySQL.
What you need is an arbitrary precision numeric field -- like the numeric type in PostgreSQL. I don't think there is an equivalent in MySQL.
If you are stuck with MySQL, then you need to do as bigfan suggested; which is to store the number as a string and then do all the calculations on the PHP end with BCMath.
|