This is an awkward error, we're having in an ASP.NET MVC 3 application. I thought it to be highly likely some bug in our code (it still might be), but I just couldn't find any indications to it.

Here's what's happening:

When the user types in a number N into a specific form, different fields within that form, so that N > 1,000 the number was divided by 1,000 and rounded to the nearest integer. For instance, 35,686 would become 36, but 35,423 would become 35. So far this happened only twice, within two weeks, although the users are using this particular form every day. Typing in the numbers again, took over the correct number.

The specifics:

The user types in, for instance 35686 (without any separators) and in 1 out of ~100 cases, 36 is stored in the DB instead of 35686. The weirdest thing is, that it gets rounded. Usually casting a doubly value, such as 35.686 would just cut off the decimal digits and result in 35.

As our users are mostly using the German culture we thought, somebody wrote 35.686 (. being the German thousands delimiter) and it got casted to integer. However, this wouldn't cause a rounding (or would it) and anyway - when we tested it, whatever language culture (English and German) we used and whatever delimiter (, and .) we always got an Exception from the server indicating, the number should be without delimiters.

Checking the application, there are no occurrences of Math.Round, Round or round in C# code, nor JS code. Neither could I find any 0.5 (the simplest way to round a double to the nearest integer is +0.5 and cast to int). I also didn't find any division by 1,000.

Is there anything we might have missed? The browser which is used by our users is IE 11 with Windows 7. The application is running on Windows Server 2012 on the latest version of .Net in IIS. Do you have any ideas?

Clarifications:

As I said, the error happened only twice in production so far and we weren't able to reproduce it anyhow. Although JavaScript is using the numbers in order to calculate and display other values next to the form, the form itself is ultimately being submitted simply as HTML. The whole code around this form is quite large >1k LOC and since we weren't able to reproduce it, there is no way for us to share the specific parts which might help finding a bug. However within the C# class, the type is an integer. So the conversion should happen somewhere in the browser or in the middleware?

Related posts

Recent Viewed