Currency 7.x-2.x contains a class called CurrencyLocalePattern that can be used to format/display prices using the current user's localization. For a price of EUR123456.78, Dutch users would see €123.456,78, American users would see €123,456.78, and Hindi users would see € 1,23,456.78, exactly as they expect prices to be formatted. Here's a short usage example:
$currency_code = 'EUR';
// Make sure the price is a float.
$price = 123456.78;
$currency = currency_load($currency_code);
// This loads the correct formatting pattern based on current environment variables, such as language and country.
$locale_pattern = CurrencyLocalePattern::loadFromEnv();
echo $locale_pattern->format($currency, $price);
Comments
Comment #1
xanoThis would greatly reduce the size of basic_cart_price_format(), while also making it incredibly more flexible.
Comment #2
alex dicianu commentedNice module!! This could be an interesting addition to Basic Cart.
Comment #3
xanoNote that prices can still be floats, but it's better to use numeric strings to prevent precision loss:
Comment #4
xanoNote that Payment now uses Currency for price formatting as well if it is enabled.
Comment #5
jenlamptonI think this sounds like a great addition, moving to the 3.x version for consideration there.
Comment #6
norman.lolThank you everyone for taking the time to report and discuss this issue. 🙇🏻♂️
As the Drupal 7 versions of this module are no longer supported, I’ll be closing this issue. 🔚
Huge thanks and credit to everyone who contributed in any way. ✨