Any idea how to support prices which have more decimal places than a currency supports in Drupal Commerce?

Use case is that I'm trying to build a website which has some very small parts, whose unit price can have factions of cents ie a small bearing which has a unit price of $0.05742.

Typical users would order 1000s at a time and price is rounded to nearest cent at payment time.

But a commerce_price (in USD) only supports 'whole' cents (to reflect the minor unit format). Entering 0.05472 in the price field causes rounding to 0.05 and this rounded value is also the value written out to the db.

Any suggestions?


1 Answer 1


Commerce allows to define the amount of decimals per currency in hook_commerce_currency_info, defaulting to 2. So you could implement hook_commerce_currency_info_alter and change that for USD.

However, due to the way prices are stored (with decimals set to 2, $5.00 is stored as 500), this will affect all existing prices, so when you change it e.g to 4 decimals, then $5.00 will now just be $0.05.

So, maybe you could instead set up a virtual currency with the same name and as many decimals as you want and then let Commerce automatically handle the conversion to USD during payment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.