I'm searching for days how to format my both double and double? inputs as decimal = comma and thousand separator =dot
example:
123456.01 ==> 123.456,01
14,02 ==> 14,02
987654321,002 ==> 987.654.321,002
what i did so far:
- I checked server/local region setting
add globalization in my web.config
globalization uiCulture="fr-BE" culture="fr-BE
In my model i used the following attribute (but i'm using TextBoxFor)
[DisplayFormat(DataFormatString = "{0:N3}", ApplyFormatInEditMode = true)]
@Html.TextBoxFor( model => model.size, new {tabindex=11, id = "SizTotText", @class = "form-control input-sm calc" })
but How can I:
1- while user is typing, the number should be formatted ? I found this solution: how to format input box text as I am typing it but i cannot switch comma with Dot Fiddle
2- Created Custom helper following this post (changed decimal to double)Post
there are a lot of solution in stackoverflow but none seems to work for me.
I hope my question is clear and sorry for my bad english
EDIT:
I decided to ignore the client formatting, no more dot's and comma but i still have issue with the regional setting.
My application still treating the dot as decimal separator, how can i fix this?
and more funny, it accepts some fields and others not, although they all have the same attribute, settings ... etc see screen shot
The field that has an error is a calculated field
var url = '@Url.Action("CalculateDropPrec", "Drop")';
$('.calc').change(function () {
// get the values of the textboxes
var numUsed = $('#numUseText').val();
var totNumUsed = $('#totNumUseText').val();
$.post(url, { nUsed: numUsed, tUsed: totNumUsed }, function (response) {
$('#precText').val(response);
});
return false;
});
@Html.TextBoxFor(model => model.PerceDropTot, new {data_val = "false", id = "precText", name = "precText", @class = "form-control input-sm drop-read", placeholder = "0.0", @readonly = "readonly" })
public JsonResult CalculateDropPrec(double nUsed, double tUsed)
{
var result = CommonComputation.CalcPrecDrop(nUsed, tUsed);
return Json(result);
}