Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

What type for monetary values

default discord avatar
dawidmachonlast year
1 2

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/ ?

  • Selected Answer
    discord user avatar
    JarrodMFlesch
    last year

    @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
    last year

    Related: #1924

  • default discord avatar
    MatthiasGrandl4 months ago

    Would be nice to get a full on money field like https://craftcms.com/docs/4.x/money-fields.html

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team..