What is the best way to store people's current balance in MySQL? I'm developing somet开发者_如何学Ching like Neobux, so each user have a balance data in MySQL..
Use decimal(10,2)
. float
is susceptible to rounding errors, see here.
For further information, you can take a look at these pages:
- What's the best datatype to properly store money/currency in MySQL?
- Storing money amounts in MySQL
I say store all of the transactions rather than just the current balance. That way you have history, and you can run different aggregates on it rather than just "final balance."
For accounting in a relational database see Ruby on Rails REST design question - transfer money between accounts
If you would just store balance then add just a input in database but if you want to store all transactions you should get a new table with username as referrer to class all transactions automatically note that, if you aren't a great programmer it would be hard to make the type of website you want so please consider purchasing a ready one .
精彩评论