Negative decimals in (parentheses) not binding - asp.net-mvc

I'm using String.Format("{0:####.00;(####.00);0.00}", Model) to display a negative currency of -1600.00 as (1600.00). However, decimal inputs in this format cannot be parsed by the model binder.
I suspect I need to change a culture setting, but I don't know where.
How do I tell my ASP.NET MVC 3 application that a decimal form input value of (1600.00) means -1600.00?
Solved. See answer below.

Solved by keeping my display templates' formatting and changing my editor templates to use a standard minus without parentheses.

Related

Orbeon XForms round-when-formatting="true"

I would like to ask if there is an option for the round-when-formatting="true" parameter combined with digits-after-decimal="0" parameter in Orbeon XForms to use Traditional rounding.
(23.6->24)(22.8->23)(23.2->23)
In the documentation section I see that it uses half to even rounding method.
round-when-formatting="true" is ideal for using rounding only in the view section, because I want the rounding only in the view, the values for the calculations in the bindings must be unrounded.
Right now there is no such option. I agree that using round-to-even() might not be the right choice. Possibly, this was used because this function in XPath 2 allows specifying a precision, while the round() function doesn't. However, this is fixed wth XPath 3. Either way, I entered issue #3226.

Mvc Kendo grid number formatting

using mvc kendo grid to represent the dat
I have decimal values likes
Actual O/P
61.05
16.00
15.92
Expected O/P This is What i am looking for
61.05
16
15.92
I used to display the value like this
Format("{0:n2}")
How can I achieve expected o/p, with the help of kendo format
Strange, that should actually work.
You can try the following formatting string as an alternative solution: {0:0.00}.
Format("{0:n2}") will force all input numbers to 2 decimal places. If you want to apply decimal places based on the value, use Format("0:0.##}") (where the number of decimal places (#) is the maximum number of decimal places you will have).
If you don't need the column to be numbers (for example for sorting, filtering or summing in the grid), then pass string values to the column and do the unusual formatting requirement in the controller.

Exponential number four not recognized in pdf generation with rotativa

I have an MVC application in which I am generating PDF from HTML pages with Rotativa. In the HTML I display some strings which I take from the resources of my application. When they are displayed as simple HTML, all the strings look good, but when the conversion to PDF is made, the exponential values are not formatted properly.
For numbers less than 4, everything looks good, like in², but when I am trying to display powers equal or higher than 4, (in⁴) the output is alterated like receiving a tilda ~ instead of the expected number. I assume this is because of the character set supported by Rotativa.
Is it possible to make Rotativa display exponential values higher than 3?
NOTE: I don't want to use <sup> x </sup> as it does not solve the problem of strings retrieved from resources.
I have tried changing the UTF enconding or font styles, but nothing worked.
I finally managed to solve this with a work-around. After I asked this question I understood how can I convert from exponential numbers, to simple string numbers, then used <sup>exponent</sup> I displayed the values from resources.
Not so pretty, but it's still working!

Allow dot and comma in numbers, not only for decimal

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?
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.

mvc regex to validate numbers as 00-99

I am working on asp.net mvc3 and i want a particular requirement that the mvc validation uses numbers from 0-99 so that i have the regex as
[RegularExpression("[0-9]{1,2}$")]
Now i want a particular requirement that the numbers from 0-9 must pass validation if it is typed as 01,02,....,09 and the rest of the numbers between as 10-99 should pass validation as a two digit number.
Please help me on this regex. I have googled it but to no avail.
can anyone suggest a regex for this type.
Just matching
"[0-9][0-9]"
should fit your requirements exactly.
It only matches if single numbers are typed in the form of 01; 02; 03 etc and matches all two digit numbers

Resources