What type for monetary values #1958
-
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/ ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@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. |
Beta Was this translation helpful? Give feedback.
-
Would be nice to get a full on money field like https://craftcms.com/docs/4.x/money-fields.html |
Beta Was this translation helpful? Give feedback.
@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.