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

xano’s picture

This would greatly reduce the size of basic_cart_price_format(), while also making it incredibly more flexible.

alex dicianu’s picture

Nice module!! This could be an interesting addition to Basic Cart.

xano’s picture

Note that prices can still be floats, but it's better to use numeric strings to prevent precision loss:

$price = '123456.78';
xano’s picture

Note that Payment now uses Currency for price formatting as well if it is enabled.

jenlampton’s picture

Version: 7.x-2.0-rc1 » 7.x-3.x-dev
Issue summary: View changes

I think this sounds like a great addition, moving to the 3.x version for consideration there.

norman.lol’s picture

Status: Active » Closed (outdated)

Thank 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. ✨

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.