Why not just using a custom formatter class? It would format values for display changing the separator and if you define static methods you can filter input. I’ve done that and it works like a charm. I’m storing decimal values (currency) with a fixed precision as integers (multiplied by 100) but one can store them in any float format.
Storing proper values in models also helps when doing any calculations.
Filtering this way helps validation anyway, since you can remove common typos before validation (or not).
BTW I’m doing the same with dates, filtering with date(‘Y-m-d’,strtotime($date)) to allow almost any input format, not just Y-m-d that the DB requires.
Yes, a custom formatter class will work, but you need to declare the class in each grid, each form, etc. The CHtml override take care of the conversion system wide. Your application code will not change at all.
I’m curious, why are you storing decimal values as integer instead of DECIMAL?
I always considered such formats as an unnecessary hassle. AFAIR I’ve never needed it for anything other than monetary values with a fixed scale of 2. Easy to remember, no need to write it down in a schema definition.
Following the PostgreSQL manual (sorry for no link, it looks I’m too new here):
I’m not saying it’s wrong in any way, just my preference. Using decimals would hint any generators using db schema how to build validation rules, but it’s not much effort to correct that by hand, especially if I do it once in a project lifetime. And I like to know where/when/how rounding happens when doing some calculations on user input.
A little digression - recently I learned that ROUND function in a popular spreadsheet software works different in cell expressions than in it’s macro language. And I learned it the hard way - by debugging.
Can you elaborate on that "etc" in your phrase ? It seems only gridviews and detailviews have this ability to format their output. It would have been nice that indeed any component could be instructed to use a formatter, but alas.
Why is there a ‘type’ property foreseen on a CDataColumn, but is it not possible to pass type information when creating for example an activeTextField so that it too would call the appropriate formatter ?
I am currently struggling to get the number formatting correclty for my locale (comma as decimal point).