How to match type c # double with type decimal in sql servek?

Closed due to the fact that the essence of the question is not clear to the participants: Igor , 0xdb , Viktor Tomilov , Eugene Krivenja , rdorn 17 Feb '18 at 8:25 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What does rounding have to do with formatting? - Igor
  • no ... I just get 1.12 semicolons, and I need a period - Den
  • where do you get it? - Igor
  • in CommandText I transfer request of a type $ "... select (price = {price})" - Den
  • String.Replace (',', '.') , And so on. First, look at the Russified MSDN. - Alias

1 answer 1

When converting to a string, the decimal separator is set based on the current locale (culture, as you like). In the Russian locale, the comma is set as a separator by default, you can look at the regional standards settings in the control panel. In your case, you can use the InvariantCulture culture-independent locale:

var price = 1.2; var priceStr = price.ToString(CultureInfo.InvariantCulture); 

For interpolated strings, you can use FormattableString.Invariant :

 sqlCommand.CommandText = FormattableString.Invariant($"...select (price = {price})"); 

PS In the case of queries to the database, it is usually accepted to use parameters , and not to stuff everything into a string:

  sqlCommand.CommandText = "... select (price = @price)"; sqlCommand.Parameters.AddWithValue("price", price); 

In this case, you will not need to worry about formatting and conversion;)