I'm using this code for exporting from my SQL Server to a .txt
file. When I use a column which is typed as float, I want to get specific view.
So this let's say that my column value is '1', I want to get a result of 1.000
, or if it is 1.1, I want the result to be 1.100
. Also if I have 0.5
, the desired result is 0.500
.
Here is my code:
SqlDataReader read = cmd.ExecuteReader();
using (StreamWriter sw = new StreamWriter(@"C:\xxx.txt"))
{
while (read.Read())
{
sw.Write(read["Quantity"].ToString());
}
}
I have already tried to convert to demical
but I get same result. Example if my column is 1, I get result 1.
I have also use padright but it doesn't take my separator.
sw.Write(read["Quantity"].ToString().PadRight(4,'0'));