edgarmtze
edgarmtze

Reputation: 25038

c# string to sqlstring losing format

I have a SQL CLR function that receives a SQLString, and I am converting the Sql string to a c# string with .ToString(), then after some computing I want to return a sring that contains doubles

   [Microsoft.SqlServer.Server.SqlFunction]
   public static string FuncCS(SqlString SQLstr){
   string CSstr = SQLstr.ToString();

     /*DO SOME STUFF*/
    for (int j = 0; j < S.ColumnCount; j++){
        for (int i = 0; i < S.RowCount; i++){
            CSstr += S[i, j].ToString("F5") + " ,  \t"; 
        }           
    }
  }

Then in SQL I receive a string but the doubles lose their decimal point and is substituted by a misplaced comma:

RESULT:

149,50625 0,00000 0,00000 0,00000 0,00000 69,06880 0,00000 0,00000 0,00000 0,00000 31,61588 0,00000 0,00000 0,00000 0,00000 8,82157 

WHAT IS NEEDED:

14.9506245839579,0,0,0,0,6.90687968992126,0,0,0,0,3.16158756810842,0,0,0,0,0.88215732592823

What do I change in the for loop?

Upvotes: 0

Views: 935

Answers (2)

cudahead
cudahead

Reputation: 153

What is the result if you just use

CSstr += S[i, j] + " ,  \t";

?

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1062630

I would imagine "culture"; try using ToString("F5", CultureInfo.InvariantCulture)

Also - look at StringBuilder for building a string in a loop.

Upvotes: 4

Related Questions