开发者

How to store User's money in database?

开发者 https://www.devze.com 2023-01-29 18:05 出处:网络
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 susceptibl

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 .

0

精彩评论

暂无评论...
验证码 换一张
取 消