Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Below is the code i am using to print data in a text file

C#
sr.WriteLine(i.ToString() + Strings.Space(3 - Strings.Len(i.ToString())) + String.Format("{0,-6:dd MMM yyyy}", ds.Tables[0].Rows[i][1]) + Strings.Space(13 - Strings.Len(String.Format("{0,-6:dd MMM yyyy}", ds.Tables[0].Rows[i][1]))) + Strings.Mid(per.ToString(), 1, 25) + Strings.Space(((35 - Strings.Mid(per.ToString(), 1, 25).Length))) + ds.Tables[0].Rows[i][3].ToString() + Strings.Space(12 - Strings.Len(ds.Tables[0].Rows[i][3].ToString())) + Strings.Space(12 - Strings.Len(ds.Tables[0].Rows[i][5].ToString())) + ds.Tables[0].Rows[i][5].ToString() + Strings.Space(12 - Strings.Len(ds.Tables[0].Rows[i][6].ToString())) + ds.Tables[0].Rows[i][6].ToString() + Strings.Space(12 - Strings.Len(ds.Tables[0].Rows[i][7].ToString())) + ds.Tables[0].Rows[i][7].ToString());


Here ds.Tables[0].Rows[i][6].ToString()is a data with value like 1000.0000, datatype is money.
i want to trim the last two 0's in this.

Please tell me how to do that.
Posted
Comments
jo.him1988 11-Jul-14 5:49am    
if you want to take only two point after decimal than you format your string like here

C#
string.Format("{0:0.##}", 256.583); // "256.58"
string.Format("{0:0.##}", 256.586); // "256.59"
string.Format("{0:0.##}", 256.58);  // "256.58"
string.Format("{0:0.##}", 256.5);   // "256.5"
string.Format("{0:0.##}", 256.0);   // "256"
 
Share this answer
 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900