I'm having a problem with localization. In Brazil, we use comma as a decimal separator, instead of dot. For example:
500,00
120,21
0,0001
I found the solution to this problem based on this answer: MVC 3 jQuery Validation/globalizing of number/decimal field
But here in Brazil, we also use "." in numbers, like:
100.000.000,00
11.125,23
And one more thing:
10.000 <> 10,000
The first one is ten thousand, and the second is simply ten.
Using the globalization plugin, when the user types the ".", it shows an validation error. I tried using the data annotation DisplayFormat, but it didn't work as expected... To "solve" this problems I'm using javascript to manually set and remove the "." from the numbers on the field, but this is very problematic when we need to change anything (and I'm sure this is one of the worst approaches I could use...). Do you guys have any idea of how to proceed in this case?
One more question: I can create a model binder (or modify the existing one) to accept this number format?
The three most spoken international auxiliary languages, Ido, Esperanto, and Interlingua, all use the comma as the decimal separator.
Leibniz was an influential mathematician, and the dot as a multiplication sign became widespread in Europe. But this solution created another problem: The dot as a multiplication sign could be confused with the decimal point. So, European mathematicians started to use a comma to separate decimals.
Great Britain and the United States are two of the few places in the world that use a period to indicate the decimal place. Many other countries use a comma instead. The decimal separator is also called the radix character.
I just found this answer.
Fixing binding to decimals
It worked perfectly in my scenario. This guy solved the exactly same problem I was having!
I just had modify a few lines of code, but the most important part was this line:
ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder());
I modified it to accept nullable values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With