How to deal with numbers and its decimal separators?

So many doubts today… :P

Well, only now I’m trying decimals numbers with Yii.

Here’s my question: In my locale, we use ‘,’ as decimal separator. So, I want my users to insert their number fields with ‘,’, like ‘1234,56’.

Yii gives me an error: ‘it is not a number’. I think Yii internationalization should know that my decimal separator is ‘,’ and convert it to the appropriated number (and do the correct validation). And, if user changes his locale to us, he might enter decimals with ‘.’

I can say the same for dates. In my locale, Yii should understand and convert dates submitted by users in ‘dd/mm/yyyy’ format, automatically. I have seen an idea with behaviors, but my opinion is that Yii should automatically understand and convert its locale data.

The I18N support in Yii is mainly about formatting the output, not parsing the input (which is very difficult and we’ve yet to see a good solution).

Thanks Qiang. Anyway, which solution would you recomend to parse input actually? With behaviors?

You would probably need a custom validator which will let this number format pass.

Then you would have either the validator or a beforeSave callback (which could be in a behavior) change the values to what you need them to be in the database

That’s how I’d do it

Is there anything new on this front? I am looking for a locale aware numeric input control.

Maybe this extension helps. It’s more like a workaround, though:

http://www.yiiframework.com/extension/decimali18nbehavior