Sunday, September 23, 2012

Formatting currency in Drupal Commerce

A project I've been involved in uses Drupal Commerce (DC) to manage currency and products.  Here's how to format "normal" values to be DC friendly.  Reason for doing so?  DC stores amount fields as INTEGER.  For instance, an amount of USD99 is stored as 9900 in the table.

There are several functions which you need to make this happen.

commerce_currency_decimal_to_amount(300, commerce_default_currency());

No comments: