Handling decimal separators - Wiki article
Posted 23 January 2012 - 01:12 AM
A localized web app should:
1- Display decimal values with the local decimal separator.
2- Allow entering decimal values with the local decimal separator.
I posted a wiki article explaining a procedure to get it done. Wiki article
Please add your comments, suggestions, etc, here.
Posted 23 January 2012 - 03:07 AM
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.
Posted 23 January 2012 - 09:18 AM
I'm curious, why are you storing decimal values as integer instead of DECIMAL?
Posted 23 January 2012 - 09:45 AM
Nope. You can just register your custom formatter in your config in the components-stanza. Gridviews, detailviews etc. will pick it up automatically
Posted 23 January 2012 - 04:01 PM
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.
Posted 23 January 2012 - 04:15 PM
num *= 100;
Posted 23 January 2012 - 04:16 PM
Posted 20 November 2012 - 03:32 AM
I have problem with :
foreach($this->owner->getTableSchema()->columns as $name => $column)
owner not exist, and after, the gii fail with :
Missing argument 1 for ModelCode::getTableSchema(), called in D:\Proyectos\tuDulceTarta\web\commonend\helpers\CHtml.php on line 2168 and defined
Posted 14 June 2013 - 10:55 AM
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).
Looking for a solution I found these:
Posted 17 June 2013 - 08:44 AM
Hm, perhaps I've put that etc in there a bit too enthusiasticaly. In fact, I cannot remember any other places where this would be useful stante pede.
As for the solutions in the wiki: I think a behaviour for this would blend in more into Yii. Makes me remember I wanted to publish such a thing