Pregunta

In my asp web project i've got some double type variables. This variables i have too store in sql server database. I found in the internet information that float data type will be best. BUT Sql Server accept numbers with comma like "1,3" "12,7". In asp code i've got double variables with point like "1.3" "2.7" etc... When I'am trying using numbers with comma in asp net, i'am receiving error "identifier expected". I was trying changed data type to nvachar in sql server, and works, but there is a lot of problems with using query and "Order BY columnNameWithDoubleNumber DESC" beacuse i 'am receiving results I wasn't expected. Please, could You help me with that ? :/

¿Fue útil?

Solución

You are mixing up the numbers with the text representation of the numbers. As a number, the value doesn't have any specific format, it's only when you turn the number into a string or parse a string into a number that the cultural settings come into play.

If you store the number as text in the database, it will be compared as text when you try to sort it. You should store the number as a number, then it will be sorted correctly.

If you have a double value in your ASP.NET code and send that in a query using a parameter, there is no cultural issues with the decimal separator.

If you are concatenating the decimal value into an SQL query (which is not recommended), you would use a period as decimal separator. SQL always uses period as decimal separator, just as with a double literal in your ASP.NET code.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top