Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Note where three-decimal currencies lose precision

Damian Legawiec2386c515b9a8
diff --git a/spree/core/lib/spree/money.rb b/spree/core/lib/spree/money.rb
index 82c7bf8414..a6404ba0bf 100644
--- a/spree/core/lib/spree/money.rb
+++ b/spree/core/lib/spree/money.rb
@@ -19,6 +19,12 @@ module Spree
# rather than raising — a sale is not the moment to discover a typo in a
# currency code.
#
+ # Note that Spree's money columns are `decimal(_, 2)` throughout, so a
+ # three-decimal currency still loses its last place on the way into the
+ # database. Rounding here to the currency's own precision keeps the
+ # arithmetic honest and means widening those columns would be the only
+ # change needed; it does not by itself make Spree dinar-exact.
+ #
# @param currency [String, ::Money::Currency, nil]
# @return [Integer]
def precision(currency)