DEV Community

Discussion on: How to handle a price with Ruby-on-Rails

Collapse
 
phawk profile image
Pete Hawkins

Great advice! I have seen a lot saying to always store prices as cents, but I've run into more issues with this approach than yours, particularly when it comes to supporting multiple currencies like JPY which don't have decimals units.

Collapse
 
songta17 profile image
Vorachith Phoubandith

Thanks ! Small precision that we need to know when we use this advice: during the model creation and depending of the need, we can adapt the first digit :

  • price:decimal{3,2} # value between. -9.99 and 9.99
  • price:decimal{4,2} # value between. -99.99 and 99.99
  • price:decimal{5,2} # value between. -999.99 and 999.99 etc.