5

What is the best way to store people's current balance in MySQL? I'm developing something like Neobux, so each user have a balance data in MySQL..

Rho
  • 1,010
  • 2
  • 11
  • 17

4 Answers4

13

Use decimal(10,2). float is susceptible to rounding errors, see here.

For further information, you can take a look at these pages:

Community
  • 1
  • 1
Donut
  • 110,061
  • 20
  • 134
  • 146
10

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."

Parris Varney
  • 11,320
  • 12
  • 47
  • 76
  • you would have to create a table to store the individual transactions, and link them back to the user table with a FK. – Mr Griever Dec 10 '10 at 17:56
0

For accounting in a relational database see Ruby on Rails REST design question - transfer money between accounts

Community
  • 1
  • 1
aceofspades
  • 7,568
  • 1
  • 35
  • 48
0

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 .

Achraf Almouloudi
  • 756
  • 10
  • 27