2
botti
7y

Hmmm, doing a little side project which requires me to store "money" I am uncertain if the approach should be integers with cents or dollars as decimals (19,4) in a MySQL/php project.. Any thoughts?

Comments
  • 1
    I would totally go the decimal way. Set the constraints to only allow 2 digits after the semicolon. I think it's way less error-prone
  • 2
    Store in the lowest unit of your currency as an int.

    EG:
    £123.99 -> 12399
    £0.01 -> 1

    Simply convert all values to a double or float and times by 100 when you want to render the value as cash.
  • 1
    Also, this isn't Stack Overflow. 😉
  • 0
    @DeadInside, not allowed to ask questions on devRant? To get advice from fellow developers? :)
  • 0
    @botti didn't say you weren't allowed. Who am I to tell you how to use it? I don't set the rules. I'm just inflicting my own desires for the community to not to loose its focus on being a forum for rants and mutual (emotional) support rather than tech support.
Add Comment