U
U
utyfua2016-01-22 17:17:27
PHP
utyfua, 2016-01-22 17:17:27

Mysql - store a large number (10^25) and then use it for calculations?

there is a need to store large numbers in php. in mysql I wrote to varchar(200) but it comes out 8.829090563937061e20 . how to do accurate and normal data saving. ps in some places, the processing is done in mysql itself (that is, ... set `data`=`data`/112, well, something like that). what am i doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri, 2016-01-22
@utyfua

the problem starts back in php, so
in php, numbers are converted to type float and all precision is lost.
for precise work with large numbers, the bc module is used
example for addition php.net/manual/ru/function.bcadd.php
that is, the numbers must be strictly strings
in mysql, you correctly make varchar for storage, but you cannot work with such numbers there.
based on the task, you need to think about what you can give up
either get it in php and divide php.net/manual/ru/function.bcdiv.php and then write it down again,
or if it is necessary for sorting, for example, then add a double field and duplicate it, the accuracy will be less, but it should be enough for sorting.

R
Rsa97, 2016-01-22
@Rsa97

The largest integers in MySQL are BIGINT (-9223372036854775808 ... 9223372036854775807), and BIGINT UNSIGNED (0 ... 18446744073709551615). Anything more is FLOAT and DOUBLE.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question