What type for monetary values

default discord avatar
dawidmachon
8 months ago
1 1

I would like to keep monetary (money/prices) in collections. Which type will be okay, number? But do I not lose precision on arithmetic problems?

Can I create own implementation for field compliant with: https://www.mongodb.com/docs/manual/tutorial/model-monetary-data/ ?

  • discord user avatar
    JarrodMFlesch
    Payload Team
    8 months ago

    @dawidmachon It is generally best practice to store monetary values in the smallest denomination, there are plenty of good articles out there explaining why this is the case.

    So personally I would opt to use the number field almost always (storing as cents), and then add a description that displays the amount in a dollar amount.

    1 reply
  • discord user avatar
    jacobsfletch
    Payload Team
    8 months ago

    Related: #1924

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.