silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
721 stars 821 forks source link

Currency DBField doesn't allow setting different thousands & decimals separators #8216

Open micschk opened 6 years ago

micschk commented 6 years ago

Affected Version

3., 4.

Description

In some locales, currencies use different separators, eg in Dutch (Netherlands) we use '€1.000,00' (as opposed to '$1,000.00'). The Currency field internally uses number_format(), this allows setting both characters. Allowing config values for both on Currency class and feeding them as 3rd & 4th agument fixes this (PR on its way).

Notes

robbieaverill commented 6 years ago

We use the intl PHP library already for date and time formatting, so we should change it to use NumberFormatter to handle all of this.

Quick investigation:

wernerkrauss commented 4 years ago

Any news on this issue?

wernerkrauss commented 8 months ago

I suggest to add a methods like NiceI18N() to all relevant classes for formatting the value with proper localisation. This can be deprecated for SS6 and become standard behaviour in SS6.

Relevant number formatting would be:

DBMoney already uses NumberFormatter, but calling Money's Amount is a plain DBDecimal without any localisation support.

For having (3.00) instead of -3.00 you can use https://www.php.net/manual/de/class.numberformatter.php#numberformatter.constants.currency-accounting

With a method for setting the formatter (e.g. currency vs currency-accounting) we could fine tune formatting in templates, like $MyValue.setFormatter('CURRENCY').Nice(), though I suggest to set this in a config value globally.

Related Issues: #8216