How do I store large numbers in a mysql database?

1. The company project has a functional requirement, which needs to store the number of gold coins in the game, and needs to do the gold coin ranking function.
2. If the total number of gold coins does not exceed 20, you can use the bigint field, but the gold coin data in the game will rise very fast, which does not seem to be enough.
3. Consider using scientific counting method to separate cardinality and index to store into two fields, but the maximum accuracy of the decimal field after the decimal point is 30 places, the excess will be ignored, it still feels like there will be an upper limit.
4. I would like to ask how to store this kind of no upper limit, but also relatively large numbers in the database, and can achieve sorting function?

Jun.23,2021

I know this is not a good answer

but I really want to ask, does your company have a game planner, regardless of inflation

20 places of money in units no one in the real world can achieve such wealth

Let's not talk about whether it is possible to grow so much, 20-digit money, how does this interface display, even in tens of thousands of units is also very long


read the answer of Lou 1 and the comments of the landlord on Lou 1. If you really want to store too long numbers, it will certainly exceed the exclusive number types such as int, bigint, and decimal. As Building 1 said, it is basically impossible to use numbers that are too large in reality. Even if Apple has a market capitalization of more than 40 billion yuan, it can basically be stored up with decimal.
Let me give you two suggestions.
1. The unit of data is set to ten thousand. Keep 6 decimal places with decimal,.
2. Use text or varchar or char to store it as a string, and then format the type when you use it. (generally speaking, no one plays like this, so consider the first.) second, I have seen some customers who don't know how to solve the high concurrency that they heard out of nowhere. As soon as you do the project, ask what to do if you have hundreds of thousands of visitors. As a matter of fact, their project has been running for no more than five months, and the number of visitors is only 1,800. So I also advise my brother not to think about things for too long.


varchar . Enlarge and store according to the decimal places you want to keep. For example, if you keep two decimal places, take out the value * 100 and then process it. Or 99.99, you can directly store 9999


here is my final solution, using a varchar field to completely save the data and use it to interact with the front end. In addition, the number is divided into the cardinality and the index in the scientific counting method, and then two fields are used to save the cardinality (decimal (18Power17) and the index (smallint) for sorting, that is, the sorting accuracy is not so high, so it is suitable for rankings where the accuracy is not very high.
example: a 123456789 field will be stored as "123456789", "1.23456789", "8"

Menu