Float, Numeric, Decimal and Currency localization

707 views
Skip to first unread message

Martimiz

unread,
Jan 21, 2014, 1:40:07 PM1/21/14
to silverst...@googlegroups.com
Hi all,

This has been an issue for quite some time now: localization for numeric fields doesn't really work for laguages that use different separators. At this point in version 3.1 Zend Format is used to validate input against the current locale settings, so the default en_US format will be displayed but never validate, and the localized version wil validate, but isn't displayed and cannot be parsed...

People have written workarounds and modules and posted issues (https://github.com/silverstripe/silverstripe-framework/issues/2161) but it isn't really solved. So I was working on a new set of DBFields, FormFields and templates based on and hopefully one day to replace the following classes:

  •   Float
  •   Decimal
  •   Currency
  •   NumericField
  •   CurrencyField

I have a basic working set ready, building further on Zend Format, and I hope people would be willing to look at it. I just have a few questions:

1. In the Currency field, the CurrencySymbol should be placed not in, but befiore the actual input field (now it isn't visible at all)

2. The current CurrencyField is quite complex - but it looks like the NumericField is used for Currency instead. So could we start by rebasing the CurrencyField on the NumericField, with a bit of extended functionality?

3. PHP's setlocale() function should not be used. Setting the current locale the SilverStripe way and using Zend Format should do the trick I think

4. The Currency class supports a set of (template) functions Nice and Whole, where Whole is basically round():

- Nice : €2,95
- Whole:  €3,00

I was wondering what other special ways of formatting currency would be used. For instance we use  €2,-  for whole numbers. Nice/Whole might support parameters to enable this?

5. The euro uses two decimals (the currency default) Are there currencies that use one or three or even six? Because at this point the number of decimals is set for the DBField, on creation only. We can use multiple Currency symbols for, say, a translatable site, but we cannot use different precision settings for displaying the values. We could offer a parameter for that - or create config, or. Does anyone know if Zend Locale 'knows' these defaults?

At this point I haven't looked at the Money field yet, but I suppose it won't be much different... All comments are appreciated. If you're interested I can put on GitHub the fields I now have in a module but they obviously aren't quite finished yet...

Thanks, Martine



Szabesz

unread,
Jan 21, 2014, 2:07:45 PM1/21/14
to silverst...@googlegroups.com
Hi,

Just to let you know that there is at least one language, Hungarian, when the "currency symbol" (actually, it is an abbreviation) is placed _after_ the numbers, i.e. following them.

best
Szabesz

Michael van Schaik

unread,
Jan 21, 2014, 2:13:58 PM1/21/14
to silverst...@googlegroups.com
Regarding the decimals, bitcoin is one 'currency' needing more decimals (and possibly also placing the currency symbol after the number).

A bitcoin can be divided down to 8 decimal places. Therefore, 0.00000001 BTC is the smallest amount that can be handled in a transaction.


--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-d...@googlegroups.com.
To post to this group, send email to silverst...@googlegroups.com.
Visit this group at http://groups.google.com/group/silverstripe-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Martimiz

unread,
Jan 22, 2014, 11:15:53 AM1/22/14
to silverst...@googlegroups.com

I've been looking into Zend Currency, and I think we could at least create one (or more) template functions to return a Zend formatted currency. It knows a lot of currency formats, and it wil at least create something close to a country's standard. To accomplish we could introduce a $currency_locale config option, equivalent to the more flexible but less easy to implement $currency_locale.

Any suggestions please?

Martimiz

unread,
Jan 22, 2014, 11:26:07 AM1/22/14
to silverst...@googlegroups.com

Thanks guys,

@Szabesz: looks like Zend Currency would create that format for you.

@
micschk: I'm not sure Zend supports bitcoins... As to the number of decimals - at this point Currency is defined as precision 9, scale 2 by default, but that can be customized. Don't know if anyone does that, so maybe we should enlarge the default scale, just in case?

Simon Welsh

unread,
Jan 22, 2014, 12:25:55 PM1/22/14
to silverst...@googlegroups.com
The Money field type already does this. 

Sent from my phone

colymba

unread,
Jan 22, 2014, 12:30:25 PM1/22/14
to silverst...@googlegroups.com
Some recommended storing currencies as Integer in the DB, and use the integer for calculation and so on. Then for the user, divide the value to be presented as decimal. So for example, store 3587000 in the DB for 35.87000€ ....
This might allow to specify a decimal precision on the fly, and format those accordingly to the locale?
Just a thought...

Mateusz Uzdowski

unread,
Jan 22, 2014, 3:19:45 PM1/22/14
to silverst...@googlegroups.com
On that, the "currency symbol" might not be a symbol too, it could be two letters separated from the number by a space:

100 zł
(https://www.google.co.nz/search?q=100+z%C5%82)

It's not going to be a simple regex ;-)

m
Reply all
Reply to author
Forward
0 new messages