Disable auto-formatting of number in an nvarchar()
Disable auto-formatting of number in an nvarchar()
Hi,
As we are working in a project that requires the user to save a string as the following format "100.000", it seems that for some weird reason, the editor is just removing the dot without us asking for it.
We are using the latest version available of the .Net libraries.
Is there a way to prevent that behavior?
This is really annoying as it is not the default behavior that should happen if we don't ask for it.
Best regards,
Vincent.
This question has an accepted answers - jump to answer
Answers
Is it saving
100000
as the value? Or is it folding the number down to be an integer (100
)? By guess is the latter, and that would be caused by the conversion from HTTP string data to a number.I wonder if we should be adding an extra condition in there whereby numbers with a decimal place and a trailing zero should not be cast as a number. My concern there is that some other developers would be expecting numeric data to be a number!
Possibly the best thing here is to use a set formatter to convert the number into a string with the three decimal places...
Allan
Hi Allan, it is saving it as
100000
. If we add anything else as a character like100.000e
, it is fine, if we save it with100,000
it is also fine. It only removes the dot. It also removes the dots if we send10.10.10
, it also becomes101010
.Unfortunately, we can't really use a formatter as the values could be without any dots. Basically, the values we have can be something like:
100
,100.000
,100.001
,999.050
.100
and100.000
should be different valuesWow, I have no idea what is causing that I'm afraid! In the Network Inspector in your browser, is it correctly sending
100.000
in the Ajax request data?Can you show me the server-side code you are using please?
Thanks,
Allan
Hi Allan,
Yes it is correctly sending
100.000
. Another strange behavior is that it is working fine on one computer but not on the computer from our other developer. So apparently there is something happening based on the configuration of the OS language used? (I suspect it could happen because of that)And here the server-side code:
I suspect what is happening is that the "culture" is set to be for a country / language which uses
.
as the thousands separator on the computer which is removing the.
, but not for the computer where it works as expected (this wikipedia map is interesting on this topic).Does that sound like it might be the case?
I still suspect the casting I linked to before. Could you change
.Process(Request.Form)
to be:and see if that addresses the issue please?
Thanks,
Allan
Hi Allan,
Sorry for the late answer, we just tested it and it seems to properly solve that specific issue. Thanks a lot
No problem - good to hear that did the job!
Allan